dthjnc306679 2013-05-21 17:31
浏览 66

覆盖Composer自动加载器

Background

I'm developing a series of websites which share a common engine. Something very similar to StackExchange's network of websites. Every webiste is a separate Symfony2 installation on a different Git repository, with a dependency to the engine, which is also placed on a separate repository.

 "requires": {
     ...
     "my-platform/core": "dev-master"
 }

I'm still in the early stage of development, so I'd like not have to use composer update everytime I change something in the core repository. It seems that Composer has a right tool to solve this problem but it doesn't want to work properly.

My directory structure:

Workspace
    MyPlatformCore
        src
            MyPlatform
                Core
                    SomeClass.php
        composer.json
    MyWebsiteAAA
        app
        src
        vendor
        web
        composer.json
    MyWebsiteBBB
        app
        src
        vendor
        web
        composer.json

Autoload section from composer.json from every MyWebsiteXXX repository:

"autoload": {
    "psr-0": {
        "MyPlatform": "../MyPlatformCore/src"
    }
},

Problem

If i run php composer.phar dumpautoload --optimize from MyWebsiteXXX it generates files of autoloader with wrong paths. File vendor/composer/autoload_classmap.php contains:

'MyPlatform\\Core\\...' => $vendorDir . '/myplatform/core/src/MyPlatform/Core/...php',

while it should contain:

'MyPlatform\\Core\\...' => $vendorDir . '/../MyPlatformCore/src/MyPlatform/Core/...php',

P.S. Workspace\MyPlatformCore is in fact a symlink, but it should matter, isn't it?

  • 写回答

1条回答 默认 最新

  • dongni3854 2013-05-22 23:12
    关注

    Composer does not fit your current phase of work.

    Having a working PSR-0 autoloader for your core classes will make them available to your other code. Adding this autoloader to the Composer autoloader should work, but I think it is better to integrate your core "code in progress" via symlink instead of constantly composer-updating it.

    The real benefit would be with an existing core codebase in several tagged versions, and your multiple websites using defined versions that differ from each other. You would only work on the core if there are features to be added or bugs fixed. The daily work would go into any of the websites, which might include updating this websites core files when it is time to do so.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)