3.8 KiB
Symfony Bundle Skeleton
A WORK IN PROGRESS skeleton for creating Symfony Bundles.
This skeleton is a very basic bundle with comments explaining what various bits are doing.
The bundle is called PcmExampleBundle and contains a Greeting class with a greet(): string method.
The greet() method returns a string welcoming someone who's name you can specify in the bundle configuration file.
Installing dependencies
You need to run docker compose run php before any composer commands. EG:
docker compose run php composer require symfony/twig-bundle
The Makefile has some common shorthands as usual.
Modifying this bundle
To change this bundle from pcm/example-bundle to something new there are few files you need to change.
-
Bundle PHP file and namespace
The file at
src/PcmExampleBundle.phpshould have it's class name and filename changed.If you are creating a bundle called
pcm/epic-login-bundlethe namespace should bePcm\EpicLoginwhile the class name should bePcmEpicLoginBundle.Subsequently, all namespaces should be changed to start with
pcm\epiclogin. -
composer metadata
Update the
nameanddescriptionfields of thecomposer.jsonfile with appropriate names. The name shouldYou will also need to update the PSR autoload classes with your bundle's class name.
Optionally edit the authors if required.
-
Config files
- Chamge 'bundles.php` to use your new bundle class
- Modify
services.yamlwhen required - Update
definition.yamlto specify your config structure (or remove if no config is required)
-
Test files
The
TestKernelneeds to return an array containing your bundle class.Again, namespaces need changing to whatever is appropriate.
PHPUnit testing
The bundle and it's configuration can be tested with PHPUnit.
This was a worthwhile section to add.
Installing a development version of the bundle
If you need to install the bundle to test stuff (EG to see how certain Twig templates look, etc) you can do so by using a development version of the bundle.
Preparing the composer.json file
First, make sure your Symfony project has the following in it's composer.json file:
{
"minimum-stability": "dev",
"prefer-stable": true,
}
Next, you need to add the repository to the composer.json file, just as you would any other PCM bundle:
{
"repositories": [
{
"type": "vcs",
"url": "ssh://example/bundle.git"
},
]
}
Installing the development bundle
You can now install the bundle with composer. Because the bundle does not yet have a tagged version we have to specify that it's a dev bundle alongside a branch to use. For example:
composer require pcm/example-bundle:dev-develop
The dev-develop part is specifying both that it's a dev package and that we want to use the develop branch. If you wanted to use the master branch you would specify as so: dev-master.
If a flex recipe is present it will prompt you to install it.
NOTE that the "symfony.lock" file will generate an incorrect version number "develop.9999999". This causes issues when uninstalling, so manually change this value to be dev-develop or whichever version you installed.
Updating the development bundle
You can make changes to the bundle whilst it's installed. Once you've pushed your changes with git you can run a composer update to retrieve the most recent changes:
composer update pcm/example-bundle
Uninstalling your development bundle
Make sure that the bundle version is correct in the symfony.lock file (see above) before running the usual uninstall command:
composer remove pcm/example-bundle
Creating a flex recipe
See the flex recipe repo for info on how to do this.