dqsong2010 2012-10-03 19: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 19: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.

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

报告相同问题?

悬赏问题

  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件
  • ¥150 求 《小魔指》街机游戏机整合模拟软件