ThoughtCraft
Developing With Composer

Developing With Composer

Did you know you can not only use Composer to manage dependencies, but actually develop a package alongside your dependencies?

It’s called --prefer-source and boy is it neat.

The gist of it is this: you define a repository and require the package as you would for a normal dependency, but when you go to run composer install or composer update you pass the flag --prefer-source along with it.

This brings down the entire repo of the package, and provided you have access to commit to that repo, you can easily work inside the package and push changes up just as if you were working within a submodule or subtree (an avenue I explored briefly before discovering this method).

I’ve recorded a fairly short (10 min) screencast of how to include a package from a private github repository, autoload the main file and use --prefer-source to be able to make changes directly within the package.

{% include responsive-embed url=“https://www.youtube.com/embed/fBJ5_7i06TY” %}

Author's Note: I’ve chosen to preserve these thoughts as they were originally shared. Some external links or references may no longer work. I’m leaving them intact to maintain their original context and spirit.