I'm developing an app that will consist of multiple Composer packages.
First I have the "main" app (it will be a "project" in Composer) that will contain all the necessary files and folders:
app/
public/
index.php
logs/
config.php
..etc..
This is not an issue. I just set the type as "project" in the composer file so it can be install with composer create-project foo/bar
.
I will also build a few optional extensions for the main app. They will be their own Composer packages. This isn't either an issue. I just make them into type "library" and install them with composer install foo/the-extension
.
The issue
The extensions will have their own namespaces and some of them will have their own dependencies. A couple of them will even have the same dependencies.
This is needed since all of them will are optional. You can install one or the other or all.
Currently, I've created a new folder called "/dev" in the main app where I have all my extensions while developing. Then, in the main app, I'm loading all the extensions auto loaders:
# Main apps autoloader
require_once __DIR__ . '/vendor/autoload.php';
# Extensions
require_once __DIR__ . '/dev/foo/vendor/autoload.php';
require_once __DIR__ . '/dev/bar/vendor/autoload.php';
...etc...
This works, but it comes with a few drawbacks:
- I need to change the code in the main app every time I'm going to make a commit to the main apps repo. This is a hassle and it's easy to miss something
- Potential versioning clashes. If two packages depends on the same package that gets a new update. If I miss to update both, there might be a version clash. (This have happened)
It's never good to have more than one auto loader since that can mess things up royally.
So, does anyone know of a proper way of handling this, or is it one of those "well, if it works for you, do it like that"-type of situations?
Been searching for a good solution for this a while now but haven't found any. If I missed some answer here on SO, please mark it as a duplicate and I'll remove this post.
Edit
As @sammitch points out in the answer below, I could add the extensions using Composers "repositories" key. This would remove the multiple auto loader problem. However, that will make the development flow pretty awkward:
- You make a change to an extension
- You commit and push that change to a git repo
- You do a
composer update
in the main app (to get the new commit) - Now you can test if your changes work
I rather not need to go through all that every single time I make a change the extensions code just to see if the change worked or not.