如何将程序包安装到我的框架的自定义路径?

时间:2023-01-12 20:10:58

I'm using composer version 1.0-dev

我正在使用作曲家版本1.0-dev

I read https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md and https://github.com/composer/installershave

我阅读了https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md和https://github.com/作曲家/ installershave

I have a custom module in bitbucket with this simple composer.json:

我在bitbucket中有一个自定义模块,使用这个简单的composer.json:

{
    "name": "mybitbucketuser/base",
    "type": "puppet-module",
    "require": {
        "composer/installers": "~1.0"
    }
}

In my main project I have this composer.json:

在我的主项目中,我有这个composer.json:

{
    "minimum-stability": "stable",
    "repositories": [
        {
            "type": "vcs",
            "url": "https://bitbucket.org/mybitbucketuser/fluzu-base.git"
        }
    ],
    "require": {
        "mybitbucketuser/base": "*"
    },
    "extra": {
        "installer-paths": {
            "modules/{$name}/": ["mybitbucketuser/base"]
        }
    }
}

I tried with this too:

我也试过这个:

"extra": {
    "installer-paths": {
        "modules/{$name}/": ["type:puppet-module"]
    }
}

All seems works fine but composer install the module in the default vendor dir instead in modules dir.

一切似乎都运行正常,但作曲家将模块安装在默认供应商目录中而不是模块目录中。

Whats wrong? Thanks.

怎么了?谢谢。

By the way, I'm using type puppet-module but in reality is a phalcon module.

顺便说一下,我正在使用类型木偶模块,但实际上是一个phalcon模块。

2 个解决方案

#1


I just made a test and it worked. Here is a simple example where hello-world is a package and hello-world-test requires that package.

我刚做了一个测试,但它确实有效。这是一个简单的例子,其中hello-world是一个包,而hello-world-test需要该包。

Folder structure

/
  hello-world/
    src/
      HelloWorld/
        SayHello.php
    composer.json

  hello-world-test/
    composer.json

/hello-world/src/HelloWorld/SayHello.php

<?php 

namespace HelloWorld;

class SayHello
{
    public static function world()
    {
        return 'Hello World, Composer!';
    }
}

/hello-world/composer.json

{
    "name": "me/hello-world",
    "type": "puppet-module",
    "require": {
        "composer/installers": "~1.0"
    },
    "autoload": {
        "psr-0": {
            "HelloWorld": "src/"
        }
    }
}

Then I ran

然后我跑了

cd hello-world
git init
git add *
git commit -m "Initial commit"
git tag -a 1.0.0 -m "first stable version"

Note: Composer expects a git repository here and also a version tag when the minimum-stability is set to stable. We can omit the tag if we set minimum-stability to dev.

注意:当最小稳定性设置为稳定时,Composer需要此处的git存储库以及版本标记。如果我们设置dev的最小稳定性,我们可以省略标记。


/hello-world-test/composer.json

{
    "minimum-stability": "stable",
    "repositories": [
        {
            "type": "vcs",
            "url": "../hello-world"
        }
    ],
    "require": {
        "me/hello-world": "*"
    }
}

Then I ran

然后我跑了

cd hello-world-test
composer install

Composer now automatically created a vendor folder for composer/installers and a modules folder for our hello-world package. The modules folder is created because of "type": "puppet-module" in our package.

Composer现在自动为composer / installers创建了一个vendor文件夹,为hello-world包创建了一个modules文件夹。 modules文件夹是由于我们的包中的“type”:“puppet-module”而创建的。

#2


Composer Packages Custom Installer plugin, This will fulfill your needs. Just FORK it and add your instructions in config directory under src/Installer CPCInstaller will do everything for you.

Composer Packages Custom Installer插件,这将满足您的需求。只需执行它并在src / Installer下的config目录中添加指令CPCInstaller将为您完成所有操作。

#1


I just made a test and it worked. Here is a simple example where hello-world is a package and hello-world-test requires that package.

我刚做了一个测试,但它确实有效。这是一个简单的例子,其中hello-world是一个包,而hello-world-test需要该包。

Folder structure

/
  hello-world/
    src/
      HelloWorld/
        SayHello.php
    composer.json

  hello-world-test/
    composer.json

/hello-world/src/HelloWorld/SayHello.php

<?php 

namespace HelloWorld;

class SayHello
{
    public static function world()
    {
        return 'Hello World, Composer!';
    }
}

/hello-world/composer.json

{
    "name": "me/hello-world",
    "type": "puppet-module",
    "require": {
        "composer/installers": "~1.0"
    },
    "autoload": {
        "psr-0": {
            "HelloWorld": "src/"
        }
    }
}

Then I ran

然后我跑了

cd hello-world
git init
git add *
git commit -m "Initial commit"
git tag -a 1.0.0 -m "first stable version"

Note: Composer expects a git repository here and also a version tag when the minimum-stability is set to stable. We can omit the tag if we set minimum-stability to dev.

注意:当最小稳定性设置为稳定时,Composer需要此处的git存储库以及版本标记。如果我们设置dev的最小稳定性,我们可以省略标记。


/hello-world-test/composer.json

{
    "minimum-stability": "stable",
    "repositories": [
        {
            "type": "vcs",
            "url": "../hello-world"
        }
    ],
    "require": {
        "me/hello-world": "*"
    }
}

Then I ran

然后我跑了

cd hello-world-test
composer install

Composer now automatically created a vendor folder for composer/installers and a modules folder for our hello-world package. The modules folder is created because of "type": "puppet-module" in our package.

Composer现在自动为composer / installers创建了一个vendor文件夹,为hello-world包创建了一个modules文件夹。 modules文件夹是由于我们的包中的“type”:“puppet-module”而创建的。

#2


Composer Packages Custom Installer plugin, This will fulfill your needs. Just FORK it and add your instructions in config directory under src/Installer CPCInstaller will do everything for you.

Composer Packages Custom Installer插件,这将满足您的需求。只需执行它并在src / Installer下的config目录中添加指令CPCInstaller将为您完成所有操作。