PHP Composer 自定义安装程序

3

我尝试解决这个问题已经很长时间了,但仍然无法弄清楚我的错误在哪里。

我有两个存储库想要合并,一个是应用程序,另一个是框架核心。

// Application
 - composer.json
 - public/
 - CCF/
   - core/ <- here the core package should go 
   - vendor/ <- here it goes instead

现在,我想创建一个composer包,安装到CCF/core/而不是CCF/vendor/clancats/core/etc..。所以我在以下位置创建了自定义安装程序:vendor/composer/installers/src/Composer/Installers/ClanCatsFrameworkInstaller.php

class ClanCatsFrameworkInstaller extends BaseInstaller
{
    protected $locations = array(
        'core'      => 'CCF/core/',
        'orbit'     => 'CCF/orbit/{$name}/',
    );
}

The composer.json of the core

{
    "name": "clancats/core",
    "description": "The ClanCatsFramework Core repository",
    "type": "clancatsframework-core",
    "license": "MIT",
    "require": {
        "php": ">=5.3",
        "composer/installers": "~1.0"
    }
}

composer.json of the application that should implement the core at CCF/core

{

    "type": "project",  
    "require": {
        "php": ">=5.3",
        "clancats/core": "dev-master"
    },
    "config": {
        "vendor-dir": "CCF/vendor"
    },
}

But after all that composer still installs the core package at /vendor/clancats/etc..

So my question is what is my mistake that composer won't install the core package to CCF/core/?

  • Added composer/installers to the requires.
  • I created a custom installer which defines the path to the core
  • Set the type of the core package to my custom one.

Another question that is spinning around my head, is my pattern wrong? I mean did i misunderstand how to use composer?

Github:

Thanks for your help guys :)


请添加以下内容:描述您想要做什么,期望的结果是什么,以及实际得到的结果是什么(如果不明显,那么期望和现实之间的差异是什么)。这些是获取帮助所需的基本信息 - 目前为止,您只是说明自己正在做某事,并且需要帮助,但您至少没有提出一个问题。 - Sven
@Sven 谢谢您的回复。我更新了问题,希望现在更清楚我在问什么。 - Mario
太棒了更新!现在任何人都可以帮忙。你甚至从我这里得到了一些积分。 :) - Sven
1
为什么不能把它们留在供应商目录中? - Patrick Forget
@PatrickForget 我已经核心部分完成了,但是至少轨道包 'CCF/orbit/{$name}/' 应该有自己的安装目录。 - Mario
听起来你想让核心包定义它将在父项目中的位置?我认为这有点不寻常,因为如果更多的组件这样做,它们就不会像可重用性那样好(我们必须根据依赖关系来构建我们的项目)。你是否愿意只在父项目的composer.json中指定该核心组件的安装程序路径?https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md - madebydavid
1个回答

0

所以对于遇到相同问题的每个人:

我的错误是我没有在主存储库中要求composer/installers

必须在两个存储库中都要求安装程序。

所以在这种情况下:

{
    "type": "project",  
    "require": {
        "php": ">=5.3",
        "clancats/core": "dev-master",
        "composer/installers": "~1.0"
    },
    "config": {
        "vendor-dir": "CCF/vendor"
    },
}

解决问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接