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.
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.
php composer.phar create-project symfony/framework-standard-edition demo/ 2.4.1 cd demo
(for example src/Company/DemoBundle
)
php app/console generate:bundle cd src/Company/DemoBundle/
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
src/Company/DemoBundle/composer.json
:
{ "name" : "company/demobundle", "description" : "A demo bundle", "type" : "symfony-bundle", "authors" : [{ "name" : "demo", "email" : "[email protected]" }], "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:
[...] "require" : { [...] "company/demobundle" : "dev-master" }, "repositories" : [{ "type" : "vcs", "url" : "https://github.com/Company/DemoBundle.git" }], [...]
Do:
curl -sS https://getcomposer.org/installer | php php composer.phar update company/demobundle
app/AppKernel:
new Company\DemoBundle\CompanyDemoBundle(),
src/Company
folder, then manually install itYou can develop and test your bundle in your first project and use it with github and composer in your second project.
An important point to know is that you can commit into your repo from the /vendor. Indeed, composer creates a second remote called "composer" for each bundle (or package) that references the repo of the package, in order you can work on it in a working context. So the good practice is to register your package in your composer.json for all your projects and commit from your /vendor/MyCompany/MyBundle
, from any project.
As a proof, just run git remote -v
from any bundle in your vendor.
The bad practice would be to consider your bundle as a separate project and have symlinks with it. The main reason why this is the bad practice is that you won't be able to declare dependancies with your bundle. Moreover you'll have some difficulties with the deployment of your projects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With