【问题标题】:How to install your own bundle with Composer in Symfony 2.1?如何在 Symfony 2.1 中使用 Composer 安装自己的包?
【发布时间】:2012-08-18 01:51:05
【问题描述】:

我刚刚迁移到 Symfony 2.1,但我不明白,如何使用 Composer 安装我自己的包?

deps 中的 2.0.x 非常简单:

[MyOwnBundle]
  git=git@git.weboshin.ru:weboshin_cms_bundle.git
  target=/bundles/My/OwnBundle

在那之后我刚刚触发了bin/vendors update,就是这样!

但是现在没有deps 文件,我应该用 Composer 来做所有事情。请给我任何提示。

【问题讨论】:

  • 有了 Symfony 2.1,你也可以使用旧的依赖管理器! 你必须创建一个composer.json 文件来告诉 Composer 你的依赖是什么。你应该看看Symfony Standard Edition's one。然后为您的捆绑包创建另一个 composer.json
  • @Florent,请注意 Composer 工具已经有一个标签,composer-php

标签: php symfony-2.1 composer-php


【解决方案1】:

我找到了答案。

// 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"
}

【讨论】:

    【解决方案2】:

    将 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”就可以了!您甚至不需要更新自动加载文件,composer 会为您完成。唯一剩下的就是在 appkernel.php 中加载包

    【讨论】:

    猜你喜欢
    • 2012-08-10
    • 2013-08-15
    • 1970-01-01
    • 2023-03-30
    • 2012-07-23
    • 2016-04-07
    • 2021-04-20
    • 2015-04-16
    • 1970-01-01
    相关资源
    最近更新 更多