5

我正在尝试在 Bundle 中使用 Bundle,但不知何故它失败了。

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/myname/mybundle"
    }
],
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.1.*",
    (...)
    "myname/mybundle": "*"
},

到目前为止,这似乎有效。但我不知道如何在“myname/mybundle”中声明另一个依赖项。

我在 myname/mybundle 的 composer.json 文件中尝试了以下操作,但没有一个起作用:(

"repositories": [
    {
        "type": "vcs",
        "url": "url": "https://github.com/drymek/PheanstalkBundle"
    }
],
"require": {
    (...)
    "drymek/PheanstalkBundle": "dev-master"
}

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "drymek/PheanstalkBundle",
            "version": "dev-master",
            "source": {
                "url": "https://github.com/drymek/PheanstalkBundle.git",
                "type": "git",
                "reference": "master"
            }
        }
    }
],
"require": {
    (...)
    "drymek/PheanstalkBundle": "dev-master"
}

当我朗姆酒时,我composer.phar update得到的只是

- myname/mybundle dev-master requires drymek/pheanstalkbundle dev-master -> no matching package found.

4

2 回答 2

5

好的,我在这里找到了答案

它指出:Repositories are not resolved recursively. You can only add them to your main composer.json. Repository declarations of dependencies' composer.jsons are ignored

太糟糕了......但现在至少我知道将我的依赖放在哪里(在根 composer.json 文件中)

于 2012-09-14T13:15:55.497 回答
0

对于捆绑包依赖项,请参阅我的库https://github.com/AshleyDawson/MultiBundle。例如,扩展 MultiBundle 并实现 getBundles() 方法,如下所示:

<?php

namespace Acme\MyBundle;

use AshleyDawson\MultiBundle\AbstractMultiBundle;

class AcmeMyBundle extends AbstractMultiBundle
{
     /**
      * Optional: define a protected constructor to stop instantiation     outside of registerInto()
      */
     protected function __construct()
     {

     }

    /**
     * Define bundles that this bundle depends on
     */
    protected static function getBundles()
    {
        return array(
           new Acme\FooBundle\AcmeFooBundle(),
           new Acme\BarBundle\AcmeBarBundle(),
        );
    }
}

然后在 AppKernel 中注册捆绑包及其依赖项:

// app/AppKernel.php

// ...

class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...,
        );

        // Register my bundle and its dependencies
        \Acme\MyBundle\AcmeMyBundle::registerInto($bundles);

        // ...
    }
}
于 2015-05-09T23:00:19.097 回答