composer dump-autoload -o 跳过我所有的 类
composer dump-autoload -o skips all my classes
我刚刚升级到 Composer 2.0,它显然对解析方式做了一些修改 类...
composer dump-autoload -o
或别名 composer du -o
基本上在我的控制台中转储了很多行,文本如下:
Class MyProject\SubCategory\CoolClass located in C:/udvikling/MyProjectRoot/src/MyProjectClasses\MyProject\SubCategory\CoolClass.php does not comply with psr-4 autoloading standard. Skipping
阅读 后,我确保所有对我的名称空间和类路径有贡献的名称都大写。即 use myproject/helperclass
现在是 use MyProject/HelperClass
我的C:/udvikling/MyProjectRoot/src/composer.json包括以下
"autoload": {
"psr-4": {
"MyProject\": "MyProjectClasses/"
}
}
我通过在类名中添加一个前导反斜杠来解决这个问题:
<?php
namespace \MyProject\Core;
class Timer {
//...
但是...根据 php.net
Fully qualified names (i.e. names starting with a backslash) are not allowed in namespace declarations, because such constructs are interpreted as relative namespace expressions.
所以这似乎不是正确的选择...(我的 IDE 也给了我一条愤怒的波浪线...)
除了回到另一个版本的 composer 之外,我该如何解决这个问题?
文件结构:
C:\udvikling\MyProjectRoot -- the root of the project
C:\udvikling\MyProjectRoot\src --the php sources
C:\udvikling\MyProjectRoot\src\MyProjectClasses -- my PHP classes
C:\udvikling\MyProjectRoot\src\vendor -- my vendor stuff for composer
C:\udvikling\MyProjectRoot\src\composer.json - my composer config
显然 psr-4 的目标之一是减少文件夹深度。
The “src” and “tests” directories have to include vendor and package directory names. >This is an artifact of PSR-0 compliance.
Many find this structure to be deeper and more repetitive than necessary. This proposal suggests that an additional or superseding PSR would be useful [...]
It’s difficult to implement package-oriented autoloading via an extension or amendment to PSR-0, because PSR-0 does not allow for an intercessory path between any portions of the class name.
所以基本上,问题是在我的 MyProjectClasses
目录中,对于 class MyProject\Core\Timer
我有一个类似的目录结构:
C:\udvikling\MyProjectRoot\src\MyProjectClasses\MyProject\Core\Timer.php
.
这必须更改为不包含基本包:C:\udvikling\MyProjectRoot\src\MyProjectClasses\Core\Timer.php
我刚刚升级到 Composer 2.0,它显然对解析方式做了一些修改 类...
composer dump-autoload -o
或别名 composer du -o
基本上在我的控制台中转储了很多行,文本如下:
Class MyProject\SubCategory\CoolClass located in C:/udvikling/MyProjectRoot/src/MyProjectClasses\MyProject\SubCategory\CoolClass.php does not comply with psr-4 autoloading standard. Skipping
阅读 use myproject/helperclass
现在是 use MyProject/HelperClass
我的C:/udvikling/MyProjectRoot/src/composer.json包括以下
"autoload": {
"psr-4": {
"MyProject\": "MyProjectClasses/"
}
}
我通过在类名中添加一个前导反斜杠来解决这个问题:
<?php
namespace \MyProject\Core;
class Timer {
//...
但是...根据 php.net
Fully qualified names (i.e. names starting with a backslash) are not allowed in namespace declarations, because such constructs are interpreted as relative namespace expressions.
所以这似乎不是正确的选择...(我的 IDE 也给了我一条愤怒的波浪线...)
除了回到另一个版本的 composer 之外,我该如何解决这个问题?
文件结构:
C:\udvikling\MyProjectRoot -- the root of the project
C:\udvikling\MyProjectRoot\src --the php sources
C:\udvikling\MyProjectRoot\src\MyProjectClasses -- my PHP classes
C:\udvikling\MyProjectRoot\src\vendor -- my vendor stuff for composer
C:\udvikling\MyProjectRoot\src\composer.json - my composer config
显然 psr-4 的目标之一是减少文件夹深度。
The “src” and “tests” directories have to include vendor and package directory names. >This is an artifact of PSR-0 compliance.
Many find this structure to be deeper and more repetitive than necessary. This proposal suggests that an additional or superseding PSR would be useful [...]
It’s difficult to implement package-oriented autoloading via an extension or amendment to PSR-0, because PSR-0 does not allow for an intercessory path between any portions of the class name.
所以基本上,问题是在我的 MyProjectClasses
目录中,对于 class MyProject\Core\Timer
我有一个类似的目录结构:
C:\udvikling\MyProjectRoot\src\MyProjectClasses\MyProject\Core\Timer.php
.
这必须更改为不包含基本包:C:\udvikling\MyProjectRoot\src\MyProjectClasses\Core\Timer.php