PSR-4 autoloading with Composer

我怕爱的太早我们不能终老 提交于 2019-11-29 11:54:53

问题


I run a portail with composer's autoloading class system:

"autoload": {
    "psr-4": {
        "Portal\\": "src/"
    }
}

It works when I run composer.phar dump -o, for instance my class Boostrap is well referenced into vendor/composer/autoload_classmap.php file:

'Portal\\Core\\Bootstrap' => $baseDir . '/src/core/Bootstrap.php',

But when I don't run the optimized option on autoload dumping, the autoloading system doesn't works anymore:

Fatal error: Class 'Portal\Core\Bootstrap' not found in /var/www/portail/prod/web/index.php on line 7

How can I make autoloading works without -o option?


回答1:


There are two ways to fix it.

  1. change composer.json to

    "Portal\\Core\\": "src/core/"
    
  2. Or rename the core directory to Core

https://getcomposer.org/doc/04-schema.md#psr-4

The subdirectory name MUST match the case of the sub-namespace names.

http://www.php-fig.org/psr/psr-4/



来源:https://stackoverflow.com/questions/28607674/psr-4-autoloading-with-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!