0

I am running a development environment in a VM that utilises shared directories from my host machine. For a number of reasons, I have moved a couple of my packages outside of the project vendor directory and placed them at the root of the OS. This is so that when I have multiple projects running with that same dependency, I can update the source code in the dependency without having to commit and run a composer update every time.

In my composer.json, I have the following for one of my projects...

"autoload": {
    "psr-0": {
        "Product\\Common\\": "/srv/deps/php-common/src/"
    }
}

As you can see, I am attempting to load the source for the project from /srv/deps/php-common/src/. This directory can be accessed fine from apache and I have tried manually including a file from it (which also works fine). However, Composer refuses to pick up any classes there.

Attempting to instantiate Product\Common\Sample will result in PHP complaining that the class doesn't exist.

Am I doing something blatantly wrong here?

1 Answer 1

0

Am I doing something blatantly wrong here?

You probably guess it yourself, the answer is "yes".

The key feature of Composer is to add libraries in the version you need, including downloading, in a location you need not take care of (besides having to copy these files to a production machine).

If you maintain a central location of libaries, how can you be sure that they are in the correct version needed for your applications?

Also, if you add an autoloading with an absolute path, that application now depends on that exact directory structure, which has to be replicated everywhere it should get installed. While I do understand that it looks much more convenient for development time just having to care about one central copy, it is not very convenient for production, or getting new developers ready to work on that project.

Have you thought about getting some help increasing the convenience of developing by using Phing or Ant scripts? I love them. I checkout a branch with Git, and then run phing test in the main directory to start the test suite. The first step there is to run composer install, which grabs the right versions.

Alternatively, I could run phing composer to only install, but usually I am interested in running the tests. I switch to a branch, change some code and run the tests. I cannot forget to install the right library versions, it is done automatically.

Or I want to update to the most recent versions. That's one manual step that also requires running the tests afterwards, but on success the new dependencies in composer.json and composer.lock get committed and will get replicated everywhere else.

One thing that really helps with this is to either host libraries on Github or Bitbucket with the ability to download ZIP files instead of cloning the repositories - or run a local instance of Satis to generate these ZIP files. It makes installing versions really fast.

But to answer your question about autoloading: Have a look at the generated files in vendor/composer. Do they look like they should work? Does the machine see the paths, the files in there?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.