PSR-4使用Composer自动加载 [英] PSR-4 autoloading with Composer
问题描述
我使用作曲家的自动加载类系统运行portail:
autoload:{
psr-4 :{
Portal\\:src /
}
}
它运行 composer.phar dump -o
,例如我的类Boostrap被很好地引用到 vendor / composer / autoload_classmap.php
档案:
'Portal\\Core\\Bootstrap '=> $ baseDir。 '/src/core/Bootstrap.php',
但是当我不运行优化选项,自动加载系统不再工作了:
致命错误: \Core\Bootstrap'在第7行的/var/www/portail/prod/web/index.php中找不到
如何在没有 -o
选项的情况下进行自动加载?
-
将composer.json更改为
Portal\\Core\\:src / core /
-
或将
核心
目录重命名为Core
https://getcomposer.org/doc/04-schema.md#psr-4
子目录name必须匹配子命名空间名称的大小写。
http://www.php-fig.org/psr/psr-4/
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?
There is two way to fix it.
change composer.json to
"Portal\\Core\\": "src/core/"
Or rename
core
directory toCore
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/
这篇关于PSR-4使用Composer自动加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!