drxnfdx798517235 2015-05-12 14:08
浏览 47

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

I'm using composer version 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

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

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

In my main project I have this 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.

  • 写回答

2条回答 默认 最新

  • dpicx06888 2015-05-12 16:06
    关注

    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.

    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.


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

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)