Symfony2 - 创建自己的供应商包 - 项目和 git 策略 [英] Symfony2 - creating own vendor bundle - project and git strategy

查看:20
本文介绍了Symfony2 - 创建自己的供应商包 - 项目和 git 策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在考虑为实体映射和服务创建我们自己的 common 包,以便在几个单独的应用程序中使用.捆绑包应该易于修改、运行、包含和测试.我知道构建捆绑包的最佳实践,但我不知道在开发中使用什么 git 策略.

We're considering creating our own common bundle for entity mapping and services for use within few separate apps. A bundle should be easy to modify, run, include and test. I know about Best Practices for Structuring Bundles, but I don't know what git strategy to use when it comes to development.

我们应该将 common 包创建为一个完整的项目并将整个存储库提交到我们的 git 服务器,还是只为 common 包的根启动源代码控制和只推送其内容?我在 github 上的包中看到了这种方法,但我不知道以这种方式开发包的简单而舒适的方法.

Should we create common bundle as a whole project and commit whole repository to our git server, or is it better to start source control only for root of common bundle and push only its contents? I see this approach in bundles available on github, but I don't know easy and comfortable way to develop bundles that way.

推荐答案

创建一个新的空 symfony 项目

php composer.phar create-project symfony/framework-standard-edition demo/ 2.4.1
cd demo

生成新的包

(例如src/Company/DemoBundle)

php app/console generate:bundle
cd src/Company/DemoBundle/

src/Company/DemoBundle

中初始化你的github仓库

Init your github repository in src/Company/DemoBundle

git init
touch README.md
git add .
git commit -m "initial commit"
git remote add origin https://github.com/YourAccount/DemoBundle.git
git push -u origin master

添加 composer.json 文件

src/Company/DemoBundle/composer.json:

{
    "name" : "company/demobundle",
    "description" : "A demo bundle",
    "type" : "symfony-bundle",
    "authors" : [{
        "name" : "demo",
        "email" : "demo@company.com"
    }],
    "keywords" : [
        "demo bundle"
    ],
    "license" : [
        "MIT"
    ],
    "require" : {
    },
    "autoload" : {
        "psr-0" : {
            "Company\DemoBundle" : ""
        }
    },
    "target-dir" : "Company/DemoBundle",
    "repositories" : [{
    }],
    "extra" : {
    "branch-alias" : {
            "dev-master" : "some_version-dev"
        }
    }
}

现在你有你的包的基本结构

Now you have the base structure of your bundle

composer.json:

composer.json:

    [...]
    "require" : {
        [...]
        "company/demobundle" : "dev-master"
    },
    "repositories" : [{
        "type" : "vcs",
        "url" : "https://github.com/Company/DemoBundle.git"
    }],
    [...]

做:

curl -sS https://getcomposer.org/installer | php
php composer.phar update company/demobundle

应用程序/应用程序内核:

app/AppKernel:

new CompanyDemoBundleCompanyDemoBundle(),

继续努力

  • 您可以在 src/Company 文件夹中克隆您的 DemoBundle,然后手动安装它
  • 您可以使用符号链接
  • Work on it

    • You can clone your DemoBundle in the src/Company folder, then manually install it
    • You can use symlink
    • 您可以在第一个项目中开发和测试您的包,并在第二个项目中将其与 github 和 composer 结合使用.

      You can develop and test your bundle in your first project and use it with github and composer in your second project.

      这篇关于Symfony2 - 创建自己的供应商包 - 项目和 git 策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆