Symfony2 - creating own vendor bundle - project and git strategy
Create a new empty symfony project
php composer.phar create-project symfony/framework-standard-edition demo/ 2.4.1
cd demo
Generate a new bundle
(for example src/Company/DemoBundle
)
php app/console generate:bundle
cd src/Company/DemoBundle/
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
Add a composer.json file
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
Use it in another project
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(),
Work on it
- You can clone your DemoBundle in the
src/Company
folder, then manually install it - You can use symlink
Conclusion
You can develop and test your bundle in your first project and use it with github and composer in your second project.
Symfony own vendor bundle dependencies
The answer is yes. You will not find the answer inside the Symfony Core, but there is the Symfony Bundle Dependencies package that just covers this need.
In all my projects I'm using it, not because makes me cooler, but because I want to really respect the integrity of all my bundles, and without this library, my bundles have not integrity at all (it sounds like when Symfony was at 2.0 with deps files, instead of going on top of composer)
ATM, no other option.
Creating vendor bundle in symfony2 and deploying it via composer
Your current bundle structure is more suitable for the psr-4 autoloader:
{
"autoload" : {
"psr-4" : {
"Vted\\PearyBundle\\" : ""
}
}
}
Alternatively, you can use the target-dir
with psr-0. However, the psr-4 autoloader is preferred.
Annotated routing in own Symfony3 vendor bundle
It seems that you forget to add this:
app_extra:
resource: .
type: extra
in app/config/routing.yml
.
See Using the custom Loader.
Custom vendor bundle namespace not loaded
In PSR-0, your bundle structure should exactly reflect your namespace.
So, to make it works move the content of your bundle in/vendor/abdielcs/expanded-collection-bundle/abdielcs/ExpandedCollectionBundle/
Instead of/vendor/abdielcs/expanded-collection-bundle/
.
Or, use target-dir
as pointed by @OlivierHenry.
Or, use PSR-4 as almost every 3rd party bundles, plus it's recommended by Symfony:
The PSR-4 autoload standard is recommended for modern bundles
From Best practices for reusable bundles.
Related Topics
Geo-Search (Distance) in PHP/MySQL (Performance)
How to Embed Images in HTML Email
When Will _Destruct Not Be Called in PHP
Jquery Ajax Request with JSON Response, How To
Disable Deprecated Warning in Symfony 2(.7)
Use a Variable to Define a PHP Function
Sum Values in Foreach Loop PHP
How to Capture PHP Output into a Variable
File_Get_Contents Returns 403 Forbidden
How to Check If a Row Exist in the Database Using Pdo
PHP Flush/Ob_Flush Not Working
Instantiate a Class with or Without Parentheses
Generate Seo Friendly Urls (Slugs)
PHP and Mod_Fcgid: Ap_Pass_Brigade Failed in Handle_Request_Ipc Function