Composer Package Development tricks and tips

Search for a command to run...

No comments yet. Be the first to comment.
Image Generated using Midjourney I recently published this article, where I am talking about some MidJourney tricks and tips after which I got some messages saying what I Midjourney. I know my bad, I did not talk about Midjourney a lot in that articl...

Most of these tricks work with BlueWillow, Stable Diffusion, and many other models. Image generated using BlueWillow Midjourney is all over the rage right now, people are going crazy over it and trying different prompts to create beautiful artwork bu...

Photo by Towfiqu barbhuiya on Unsplash This is part 3 of the Managing your Finances article series, if you have not read part 1 and part 2, then I would recommend you to read those before starting with this article. You have started the journey and y...

Photo by micheile henderson on Unsplash This is part 2 of the Managing your Finances article series, if you have not read part 1, then you can read it here, after which you can resume this article. If you are sorted with your current financial situat...

Photo by Mathieu Stern on Unsplash Before starting the journey of Financial Freedom or even improving our finances, we should be prepared by assessing our current financial situation to avoid bumps during our journey. Think of this preparation as col...

Composer
If you are not a PHP Developer and do not care what composer is then you can skip this article and read some other interesting article on Medium.
If you are a PHP developer and do active PHP Development then there are a lot of chances that you would want to develop a Package and use it in your application.
This is a very short article (rather a tip) which will help you with package development.
If you have your package ready, with PSR-4 Autoloading and you do not want to publish it on Packagist or simply want to test it on your development environment then simply you can use composer repositories option.
Just add following code in your composer.json file where you want to use the package.
Load Package from Git Repository
It will auto-pull the Package from Github (or any other VCS) and set-it up for you to start with your development (provided you have repository access).
I was following the same and it worked flawlessly multiple developers were working on the Package and it worked like magic but then there was another catch, I wanted to avoid pushing on git and wanted to test the package in an application. composer to the rescue, composer allows local path in repository like this:
Load Package from Local Directory
It worked but the problem was before pushing the code, I had to make changes from VCS to Path in the calling application’s composer file. which was a pain, I tried searching options for commenting in composer.json file or some other options where I can keep the local and production environment together. The internet spoke the truth, No, there is no way to comment in composer.json file. but I found a work-around on stackoverflow.
Apparently, you can have multiple composer.json files in your PHP application and you can mention it run-time, which one to use for installing packages.
you can do:
composer install // or composer update
which will install the packages from composer.json file and you can do
COMPOSER=composer-local.json composer install // or composer update
which will load the packages from composer-local.json file.
Hope these tricks will be useful for you.
Thank you for reading.
Happy coding!!!