2012-08-22 88 views
6

我刚搬到了Symfony 2.1,我无法理解,我怎样才能用Composer安装我自己的软件包?如何在Symfony 2.1中使用Composer安装自己的包?

这是在2.0.x版本很容易在deps

[MyOwnBundle] 
    [email protected]:weboshin_cms_bundle.git 
    target=/bundles/My/OwnBundle 

之后,我只是触发bin/vendors update,就是这样!

但是现在没有deps文件,我应该用Composer完成所有工作。请给我任何提示。

+0

**随着Symfony的2.1也可以使用旧的依赖管理!**你必须创建一个'composer.json'文件告诉作曲什么是你的依赖。你应该看看[Symfony标准版的一个](https://github.com/symfony/symfony-standard/blob/master/composer.json)。然后为你的包创建另一个'composer.json'。 – Florent

+0

@Florent,请注意Composer工具'composer-php'已经有一个标签。 – Charles

回答

6

我找到了答案。

// my_project/compose.json: 
{ 
    "repositories": [ 
     { 
      "type": "vcs", 
      "url": "own_repository_url" 
     } 
    ], 

    // ... 

    "require": { 
     // ... 
     "own/bundle": "dev-master" 
    } 
}, 

// own_repository/own_bundle/compose.json: 
{ 
    "name": "own/bundle" 
} 
5

将composer.json文件添加到您的包中。例如,我有这对我的包之一:

{ 
    "name":  "cg/kint-bundle", 
    "type":  "symfony-bundle", 
    "description": "This bundle lets you use the Kint function in your Twig templates. Kint is a print_r() replacement which produces a structured, collapsible and escaped output", 
    "keywords": ["kint", "debug", "symfony", "bundle", "twig"], 
    "homepage": "http://github.com/barelon/CgKintBundle", 
    "license":  "MIT", 

    "authors": [ 
     { 
      "name": "Carlos Granados", 
      "homepage": "http://github.com/barelon" 
     }, 
     { 
      "name": "Symfony Community", 
      "homepage": "http://github.com/barelon/CgKintBundle" 
     } 
    ], 

    "require": { 
     "php":      ">=5.3.2", 
     "symfony/framework-bundle": ">=2.0.0", 
     "raveren/kint":    "dev-master" 
    }, 

    "minimum-stability": "dev", 

    "autoload": { 
     "psr-0": { 
      "Cg\\KintBundle": "" 
     } 
    }, 

    "target-dir": "Cg/KintBundle" 
} 

你的包然后添加到packagist.org。这很简单,基本上你只需要提供你的git地址,剩下的就完成了。

一旦您的软件包在packagist中可用,只需将它作为symfony项目的composer.json文件中的依赖项添加即可。在我的情况下,我有:

"require": { 
    .... 
    "cg/kint-bundle": "*" 
}, 

然后,只需在symfony目录中运行“composer update”,这就是全部!你甚至不需要更新autoload文件,作曲家会为你做。剩下的唯一东西就是加载appkernel.php中的包

+3

请注意,“添加到packagist”仅适用于开放源代码包,对于封闭源代码包,请参阅https://getcomposer.org/doc/05-repositories.md#vcs和https://getcomposer.org/doc /articles/handling-private-packages-with-satis.md – Seldaek

+6

有人知道'symfony-bundle'意味着什么吗?使用这种类型的后果是什么? – greg0ire

相关问题