Description

I'm writing my symfony2 bundle. I created a repository, connected it through the composer and edited it directly in the vendor directory, everything is fine, but new files do not want to connect through the composer autoloader .

Problem:

I noticed that composer writes all my files to vendor/composer/autoload_classmap.php and accordingly if you add a new file there with your hands or make composer update -o then everything is fine. But constantly straining to add.

Question

How can I tell the composer that I have a PSR-4 and let all the files connect automatically, and not statically save to vendor/composer/autoload_classmap.php ?

Here is the autoload in the composer.json project:

 ... "autoload": { "psr-4": { "": "src/" } }, ... 

But autoload in composer.json bundle

 ... "autoload": { "psr-4": { "NameSpace\\MyBundle\\": "../" } } ... 

With that in vendor/composer/autoload_psr4.php my bundle is there, but apparently the settings are curves, because I have no src directory in the bundle:

 ... 'NameSpace\\ MyBundle\\' => array($vendorDir . '/namespace'), '' => array($baseDir . '/src'), ... 
  • add a bundle to ruta composer.json as a dependency - etki
  • @Etki saboi itself)) The problem is not that - korytoff
  • I mean, either do not use optimization when building an autoloader, or refer not to an external repository, but to a local folder - etki
  • @Etki Ie this is all because of the optimization of the autoloader? - korytoff
  • Yes, optimization means dropping all file paths into an array and not using dynamic class name resolution - etki

1 answer 1

As a result, the problem was solved by changing the file composer.json in its library:

 ... "autoload": { "psr-4": { "NameSpace\\MyBundle\\": "" } } ... 

Initially, the path was specified as ../ , but it turned out to be a rather empty string to register.

Now the usual composer update gives the desired result.