Reputation: 1120
I am developing a symfony2
application and I am trying to include my custom yaml config located in /src/AppBundle/Resources/Config/general.yml
I have followed example provided here http://symfony.com/doc/current/cookbook/bundles/extension.html and created in src/AppBundle/DependencyInjection/AppExtension.php
file with the following content:
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Translation\Loader\YamlFileLoader;
class AppExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader(
$container,
new FileLocator("@AppBundle/Resources/config')
);
$loader->load('general.yml');
}
}
However, I stuck at this point and don't know how to make symfony execute this file and load the config.
Upvotes: 3
Views: 2580
Reputation: 12730
Since I don't see the content of your general.yml file I can suggest you to use something like below (I haven't tested it but it should be fine).
Assuming that this is your general.yml
doctrine:
orm:
entity_managers:
encrypt:
mappings:
MyEncryptBundle:
dir: Entity
type: annotations
prefix: My\EncryptBundle\Entity
Instead of creating this yml file and importing it, you can directly set all of it in your DependencyInjection so it would be something like below.
namespace Application\FrontendBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class ApplicationFrontendExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml'); # another file of yours
$loader->load('controllers.yml'); # another file of yours
$loader->load('repositories.yml'); # another file of yours
}
public function prepend(ContainerBuilder $container)
{
$container->prependExtensionConfig(
'doctrine',
[
'orm' => [
'entity_managers' => [
'encrypt' => [
'mappings' => [
'MyEncryptBundle' => [
'dir' => 'Entity',
'type' => 'annotation',
'prefix' => 'My\EncryptBundle\Entity'
]
]
]
]
]
]
);
}
}
Or you can do something like this instead.
Upvotes: 2