简体   繁体   English

在composer中指定PSR-0命名空间的根目录

[英]Specify the root for of PSR-0 namespace in composer

I current have the following composer.json file: 我目前有以下composer.json文件:

{
    "require": {
        "slim/slim": "2.*"
    },
    "autoload": {
        "psr-0": { "App": "app/" }
    }
}

I'm trying to instantiate a class in the app folder, but the autoloader is looking for: 我正在尝试在app文件夹中实例化一个类,但自动加载器正在寻找:

/var/www/framework/app//App/App.php

Obviously the second parameter is the folder containing the namespace rather than the root of the namespace. 显然,第二个参数是包含命名空间的文件夹,而不是命名空间的根。 How can I make it load: 我怎样才能加载它:

/var/www/framework/app/App.php

Thanks in advance! 提前致谢!

The easiest solution is to rename the folder from app to App and set 最简单的解决方案是将文件夹从app重命名为App并进行设置

"psr-0": { "App": "." }

I guess else you need a custom autoloader. 我想其他你需要一个自定义自动装载机。 However, I recommend to follow some proven use-cases: 但是,我建议遵循一些经过验证的用例:

src/App/App.php

with

"psr-0": { "App": "src" }

Looks curious, but I must say, that I would never call a namespace or class (or even both) just App ;) It doesn't say anything and with aliasing ( use MyApplication as App ) there is no reason anymore to write as short identifiers as possible. 看起来好奇,但我必须说,我永远不会调用命名空间或类(甚至两者)只是App ;)它没有说任何东西和别名( use MyApplication as App )没有理由再写为short标识符尽可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM