M
M
Maxim2015-10-15 03:28:38
symfony
Maxim, 2015-10-15 03:28:38

How to create a Symfony2 project with PHP configs, not YAML?

Hello! Tell me, please, how to create a new project so that all the configs in app/config/*were *.phpfiles, and not *.yaml?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin, 2015-10-15
@ua6xh

In the bundle you have a DependencyInjection/AcmeAppExtension.php.
If its contents are brought approximately to this form, then it should work (although I myself have not tried to do this).

<?php

namespace Acme\AppBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * 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}
 * @codeCoverageIgnore
 */

class AcmeAppExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $this->processConfiguration($configuration, $configs);

        $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__ . '/../config/'));
        $loader->load('services.php');

        if ($container->getParameter('kernel.environment') == 'dev') {
            $loader->load('services_dev.php');
        }

        if ($container->getParameter('kernel.environment') == 'test') {
            $loader->load('services_test.php');
        }
    }
}

PS I personally also think that it is a big stupidity to abandon yml in favor of php-configs: this violates the basic principle of configuration - its determinism. In the php-config, you can twist some kind of logic when calculating one or another parameter, which will negatively affect the convenience of project support.

S
Sergeyj, 2015-10-15
@sayber

It is possible to specify in the php parameters (as when creating a bundle).
Although I can't imagine the reason to create php configs.

S
shagguboy, 2015-10-15
@shagguboy

заменить по вкусу:
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question