[英]Composer autoload few paths as one namespace
I have this folders structure: 我有这个文件夹结构:
core/
core/db/
core/db/beans
I have classes with namespace AAA\\Core\\DataBase;
我有带有namespace AAA\\Core\\DataBase;
in the core/db/
and in core/db/beans
. 在core/db/
和core/db/beans
。
In my composer.json file I have: 在我的composer.json文件中,我有:
"autoload": {
"psr-4": {
"AAA\\Core\\": "core/",
"AAA\\Core\\DataBase\\": "core/db/"
}
}
After that I can use classes from core/
folder with use AAA\\Core\\DataBase\\ClassName;
之后,我可以使用core/
文件夹中的类,并use AAA\\Core\\DataBase\\ClassName;
but can't from core/db/beans
. 但不能从core/db/beans
。 I received "Fatal error: Class not found". 我收到“致命错误:找不到类”。 How can I add few folders to the same namespace? 如何将几个文件夹添加到同一名称空间? Is it possible? 可能吗?
As PSR-4 standard goes: 按照PSR-4标准:
When loading a file that corresponds to a fully qualified class name 加载与完全限定的类名相对应的文件时
- A contiguous series of one or more leading namespace and sub-namespace names, not including the leading namespace separator, in the fully qualified class name (a "namespace prefix") corresponds to at least one "base directory". 在完全限定的类名(“名称空间前缀”)中,一个或多个前导的名称空间和子名称空间名称(不包括前导的名称空间分隔符)的连续序列对应于至少一个“基本目录”。
- The contiguous sub-namespace names after the "namespace prefix" correspond to a subdirectory within a "base directory", in which the namespace separators represent directory separators. “名称空间前缀”之后的连续子名称空间名称对应于“基本目录”内的子目录,其中名称空间分隔符表示目录分隔符。 The subdirectory name MUST match the case of the sub-namespace names. 子目录名称必须与子命名空间名称的大小写匹配。
Therefore, your namespaces must correspond with your folder structure. 因此,您的名称空间必须与您的文件夹结构相对应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.