After spending some time, I finally understood the solution. Maybe it'll be useful for someone like me and will save you some time, so I've decided that I have to share it here.
Assuming that you have the following directory structure (relative to your project root directory):
composer.json config config/composition-root.php local local/bar-project local/bar-project/composer.json local/bar-project/src local/bar-project/src/Bar.php public public/index.php src src/Foo.php
In this example you may see that the local folder is meant for nested projects of your company, e.g. bar-project. But you could configure any other layout, if you wish.
Each project has to have its own composer.json file, e.g. root composer.json and local/bar-project/composer.json. Then their contents would be as follows:
(root composer.json:)
{ "name": "your-company/foo-project", "require": { "php": "^7", "your-company/bar-project": "@dev" }, "autoload": { "psr-4": { "YourCompany\\FooProject\\": "src/" } }, "repositories": [ { "type": "path", "url": "local/bar-project" } ] }
(local/bar-project/composer.json:)
{ "name": "your-company/bar-project", "autoload": { "psr-4": { "YourCompany\\BarProject\\": "src/" } } }
If, for example, you wish to locate each project in a separate sibling directory, as follows:
your-company your-company/foo-project your-company/foo-project/composer.json your-company/foo-project/config your-company/foo-project/config/composition-root.php your-company/foo-project/public your-company/foo-project/public/index.php your-company/foo-project/src your-company/foo-project/src/Foo.php your-company/bar-project your-company/bar-project/composer.json your-company/bar-project/src your-company/bar-project/src/Bar.php
- then you need to link to respective directory in repositories section:
"repositories": [ { "type": "path", "url": "../bar-project" } ]
After that don't forget to composer update (or even rm -rf vendor && composer update -v as the docs suggest)! Under the hood, composer will create a vendor/your-company/bar-project symlink that targets to local/bar-project (or ../bar-project respectively).
Assuming that your public/index.php is just a front controller, e.g.:
<?php require_once __DIR__ . '/../config/composition-root.php';
Then your config/composition-root.php would be:
<?php declare(strict_types=1); use YourCompany\BarProject\Bar; use YourCompany\FooProject\Foo; require_once __DIR__ . '/../vendor/autoload.php'; $bar = new Bar(); $foo = new Foo($bar); $foo->greet();
sammitch/foois the package name and has literally nothing to do with where it is located. Will construct a list of available packages based on its configured repos, in this case fetching the composer.json from the specified local git repo, and then composer handles the rest. Thesammitch/foopackage is copied to the current app'svendorfolder the same as any other package.