Skip to content

Commit

Permalink
Merge pull request #104 from szymach/2.0
Browse files Browse the repository at this point in the history
Load extensions configuration via compiler pass
  • Loading branch information
rn0 authored Apr 30, 2019
2 parents eac7e07 + d9bdfbb commit 28e6305
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
10 changes: 8 additions & 2 deletions DataGridBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\DataGridBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use FSi\Bundle\DataGridBundle\DependencyInjection\Compiler\DataGridPass;
use FSi\Bundle\DataGridBundle\DependencyInjection\Compiler\ExtensionsPass;
use FSi\Bundle\DataGridBundle\DependencyInjection\Compiler\TemplatePathPass;
use FSi\Bundle\DataGridBundle\DependencyInjection\FSIDataGridExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class DataGridBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
// this needs to be first, otherwise the extensions will not be loaded in
// DataGridPass
$container->addCompilerPass(new ExtensionsPass());
$container->addCompilerPass(new DataGridPass());
$container->addCompilerPass(new TemplatePathPass());
}
Expand Down
31 changes: 31 additions & 0 deletions DependencyInjection/Compiler/ExtensionsPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* (c) FSi sp. z o.o. <info@fsi.pl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace FSi\Bundle\DataGridBundle\DependencyInjection\Compiler;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

final class ExtensionsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
if (true === $container->hasExtension('doctrine')) {
$loader->load('datagrid_doctrine.xml');
}

if (true === $container->hasExtension('stof_doctrine_extensions')) {
$loader->load('datagrid_gedmo.xml');
}
}
}
8 changes: 0 additions & 8 deletions DependencyInjection/FSIDataGridExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('datagrid.twig.themes', $config['twig']['themes']);
}

if (true === $container->hasExtension('doctrine')) {
$loader->load('datagrid_doctrine.xml');
}

if (true === $container->hasExtension('stof_doctrine_extensions')) {
$loader->load('datagrid_gedmo.xml');
}

if (method_exists($container, 'registerForAutoconfiguration')) {
$container->registerForAutoconfiguration(DataGridExtensionInterface::class)
->addTag('datagrid.extension');
Expand Down

0 comments on commit 28e6305

Please # to comment.