user2906759
user2906759

Reputation: 831

Why does composer need to manually generate autoload files?

When installing libraries with composer it generates a autoload_classmap.php in order to hook up the different namespaces with classes. For example:

'PHPUnit_Framework_Assert' => $vendorDir . '/phpunit/phpunit/src/Framework/Assert.php'

Why is this even needed when it can be done with a simple spl_autoload_register() and bypass the whole need for generating new files every time?

Upvotes: 0

Views: 357

Answers (2)

Composer uses a PSR-0/4 autoloader with some features to register non compliant with PSR-0/4 classes and autoloaders.

If you use the option --optimize-autoloader (-o), It will generate a class map to get a faster autoloader.

References

Upvotes: 0

deceze
deceze

Reputation: 522510

Because generating a list of all classes and where they can be found is an expensive task which you really don't want to have to do every single time the autoloader is invoked, or even just every time for a new request. You just need to compile this information once every time your vendor folder changes and store it somewhere. And that's exactly what Composer does.

Upvotes: 2

Related Questions