Hello again! It’s my second post today! I’m electric!
I am developing a project that uses a package I’m developing too. So, it is a real time test project. I find a new way to do something and write it inside my package and uses that.
But sometimes this is a boring work. I am sharing my package in the Packagist website using Composer, and everything I change I have to commit, push to GitHub and update my project with Composer, to get the new code I’ve wrote. That’s a very very bad idea.
Yesterday I was talking with my friend @diegoholiveira about to test the package locally and we’ve found a easy solution. You can change the package you are developing and use that in the project that uses it. We were trying to find an easy way to do that using Composer, but the solution was easier than that. Just use symbolic links.
Ok. Let’s assume you are developing a website. This website have to generate passwords with some particularities. So you decide to develop a package to provide this password generation and use it inside the website project. So you have 2 distinct projects:
Let’s assume your password-generator is a package inside the “yourname” vendor. So the package name will be:
First you have to have installed at least a basic version of your package. You can submit a very basic package to Packagist, where you will install from. You add the package information inside your
composer.json file and
composer install or
Good. If you were installing this package inside your website project you will have the follow structure using Composer:
But you already have you code inside:
So, create a symbolic link from your package to your website:
ln -s /home/me/projects/password-generator /home/me/projects/website/vendor/myname/password-generator
After that you must update the Composer autoload to find that new files. Inside your /website folder:
Ready! Everything you change in the package password-generator you will can use inside your website project. If you created some new class, maybe you must run
composer dump-autoload again to update files.
When you want, just commit, push your package to GitHub and share!