dqsong2010 2012-10-03 11:16
浏览 229
已采纳

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

I current have the following composer.json file:

{
    "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:

/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!

  • 写回答

1条回答 默认 最新

  • dongshan4518 2012-10-03 11:45
    关注

    The easiest solution is to rename the folder from app to App and set

    "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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部