我正在尝试在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.
答案 0 :(得分:5)
好的,我找到了答案here
它声明: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文件中)
答案 1 :(得分: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中注册bundle及其依赖项:
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...,
);
// Register my bundle and its dependencies
\Acme\MyBundle\AcmeMyBundle::registerInto($bundles);
// ...
}
}