11

I'm starting to use Composer in a project, in which I historically had all the dependencies under version control.

This project currently uses the Symfony 2 autoloader. Because Composer comes with its own autoloading mechanism (vendor/autoload.php), that makes me wonder if I still need to use the Symfony ClassLoader.

I assume that I could just use the Composer autoloader to autoload my project classes as well:

$loader = require 'vendor/autoload.php';
$loader->add('MyProject', 'src');

Is there any drawback in using the Composer autoloader for the whole project?

Are there features the Symfony autoloader offers that I won't find in the Composer autoloader?

Maerlyn
  • 33,687
  • 18
  • 94
  • 85
BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

13

You can just require the composer autoloader. The only feature it lacks is the ApcClassLoader which speeds things up with APC but introduces some complexity (you have to clear the cache when deploying). Using composer's -o flag (when installing or running dump-autoload) will give you a classmap one which is more or less equivalent to APC in terms of speed but without the complexity.

Seldaek
  • 40,986
  • 9
  • 97
  • 77
  • To use the -o (--optimize) option, you will need to generate the classmap with 'composer dump-autoload --optimize' on each deployment instead of clearing the cache, but agreed that it's far more foolproof. Very easy to get cache key conflicts between stages or releases, even if you clear the cache the right way as described here: http://stackoverflow.com/a/12859565/160565 – Nathan Stretch Mar 27 '14 at 07:11