Monolithic Repositories with Composer and Relative Autoloading

Written by Benjamin Eberlei - - Aggregated on Saturday August 8, 2015

Monolithic Repositories with Composer and Relative Autoloading

Just was reminded on Twitter by Samuel that there is a way for monolithic PHP repositories with multiple components that I haven’t mentioned in my previous post.

It relies on a new composer.json for each component and uses the autoloading capabilities of Composer in a hackish way.

Assume we have two components located in components/foo and components/bar, then if bar depends on foo, it could define its components/bar/composer.json file as:

{
    "autoload": {
        "psr-0": {
            "Foo": "../foo/src/"
        }
    }
}

This approach is very simple to start with, however it has some downsides you must take into account:

I think this approach is ok, if you are only sharing a small number of components that don’t define their own dependencies. The Fiddler approach however solves all these problems by forcing to rely on the same dependencies in a project globally and only once.


« ESI - Full page caching with Symfony2 - Jordi Boggiano

Benjamin Eberlei - The ContainerTest »