Create a Bundle
Create a Bundle Manually
First you need to specify name and namespace of your bundle. Symfony framework already has best practices for bundle structure and bundle name and we recommend to follow these practices and use them.
Let us assume that we want to create the AcmeDemoBundle and put it under the namespace Acme\Bundle\DemoBundle
in the /src
directory. We need to create the corresponding directory structure and the bundle file with the following content:
namespace Acme\Bundle\DemoBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeDemoBundle extends Bundle
{
}
Basically, it is a regular Symfony bundle. The only difference is in the way it will be enabled (see chapter Enable a Bundle).
Create a Bundle Service Container Extension
For a load configuration files you need to create Service Container Extension. See Symfony Configuration Files
namespace Acme\Bundle\DemoBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class AcmeDemoExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
// register services configuration
$loader->load('services.yml');
// register other configurations in the same way
$loader->load('services_checkout.yml');
}
}
Create basic Resources/config/services.yml
for define service parameters. See Symfony Service Parameters
services:
Enable a Bundle
Now you have all the required files to enable the new bundle. To enable the bundle:
Create a Resources/config/oro/bundles.yml file with the following content:
bundles:
- { name: Acme\Bundle\DemoBundle\AcmeDemoBundle, priority: 255 }
This file provides a list of bundles to register. All such files are automatically parsed to load the required bundles.
Regenerate the application cache using console command
cache:clear
:user@host:/var/www/vhosts/platform-application$ php bin/console cache:clear Clearing the cache for the dev environment with debug true
Note
If you are working in production environment, use parameter
--env=prod
with the command.Check if your bundle is registered and active with following command:
php bin/console debug:container --parameter=kernel.bundles --format=json | grep AcmeDemoBundle
Note
Replace grep argument with your bundle’s proper name
When your bundle is registered and active, the following output (or a similar one) will be displayed in the console after running the command:
"AcmeDemoBundle": "Acme\\Bundle\\DemoBundle\\AcmeDemoBundle",