Ver código fonte

Load admin exporter service conditionally

Grégoire Paris 8 anos atrás
pai
commit
c41978a781

+ 5 - 1
DependencyInjection/SonataAdminExtension.php

@@ -60,8 +60,12 @@ class SonataAdminExtension extends Extension implements PrependExtensionInterfac
         $loader->load('block.xml');
         $loader->load('block.xml');
         $loader->load('menu.xml');
         $loader->load('menu.xml');
 
 
+        if (isset($bundles['SonataExporterBundle'])) {
+            $loader->load('exporter.xml');
+        }
+
+        // NEXT_MAJOR : remove this block
         if (method_exists('Symfony\Component\DependencyInjection\Definition', 'setDeprecated')) {
         if (method_exists('Symfony\Component\DependencyInjection\Definition', 'setDeprecated')) {
-            // NEXT_MAJOR : remove this block
             $container->getDefinition('sonata.admin.exporter')->setDeprecated(
             $container->getDefinition('sonata.admin.exporter')->setDeprecated(
                 'The service "%service_id%" is deprecated in favor of the "sonata.exporter.exporter" service'
                 'The service "%service_id%" is deprecated in favor of the "sonata.exporter.exporter" service'
             );
             );

+ 8 - 0
Resources/config/exporter.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+    <services>
+        <service id="sonata.admin.admin_exporter" class="Sonata\AdminBundle\Bridge\Exporter\AdminExporter">
+            <argument type="service" id="sonata.exporter.exporter"/>
+        </service>
+    </services>
+</container>

+ 33 - 0
Tests/DependencyInjection/SonataAdminExtensionTest.php

@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of the Sonata Project package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\DependencyInjection;
+
+use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
+use Sonata\AdminBundle\DependencyInjection\SonataAdminExtension;
+
+class SonataAdminExtensionTest extends AbstractExtensionTestCase
+{
+    public function testLoadsExporterServiceDefinitionWhenExporterBundleIsRegistered()
+    {
+        $this->container->setParameter('kernel.bundles', array('SonataExporterBundle' => 'whatever'));
+        $this->load();
+        $this->assertContainerBuilderHasService(
+            'sonata.admin.admin_exporter',
+            'Sonata\AdminBundle\Bridge\Exporter\AdminExporter'
+        );
+    }
+
+    protected function getContainerExtensions()
+    {
+        return array(new SonataAdminExtension());
+    }
+}

+ 1 - 0
composer.json

@@ -45,6 +45,7 @@
     "require-dev": {
     "require-dev": {
         "jms/di-extra-bundle": "^1.7",
         "jms/di-extra-bundle": "^1.7",
         "jms/translation-bundle": "^1.2",
         "jms/translation-bundle": "^1.2",
+        "matthiasnoback/symfony-dependency-injection-test": "^0.1 || ^1.0",
         "sensio/generator-bundle": "^2.3 || ^3.0",
         "sensio/generator-bundle": "^2.3 || ^3.0",
         "sllh/php-cs-fixer-styleci-bridge": "^2.0",
         "sllh/php-cs-fixer-styleci-bridge": "^2.0",
         "sonata-project/exporter": "^1.7",
         "sonata-project/exporter": "^1.7",