Browse Source

changed injection of container to injection of pool

Ahmet Akbana 8 năm trước cách đây
mục cha
commit
a24bfb209a

+ 1 - 1
Resources/config/core.xml

@@ -66,7 +66,7 @@
         </service>
         </service>
         <!-- twig -->
         <!-- twig -->
         <service id="sonata.admin.twig.global" class="Sonata\AdminBundle\Twig\GlobalVariables">
         <service id="sonata.admin.twig.global" class="Sonata\AdminBundle\Twig\GlobalVariables">
-            <argument type="service" id="service_container"/>
+            <argument type="service" id="sonata.admin.pool"/>
         </service>
         </service>
     </services>
     </services>
 </container>
 </container>

+ 27 - 6
Twig/GlobalVariables.php

@@ -15,23 +15,44 @@ use Sonata\AdminBundle\Admin\Pool;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 
 /**
 /**
- * Class GlobalVariables.
- *
  * @author  Thomas Rabaix <thomas.rabaix@sonata-project.org>
  * @author  Thomas Rabaix <thomas.rabaix@sonata-project.org>
  */
  */
 class GlobalVariables
 class GlobalVariables
 {
 {
     /**
     /**
      * @var ContainerInterface
      * @var ContainerInterface
+     *
+     * @deprecated Since version 3.x, will be removed in 4.0.
+     * NEXT_MAJOR : remove this property
      */
      */
     protected $container;
     protected $container;
 
 
     /**
     /**
-     * @param ContainerInterface $container
+     * @var Pool
      */
      */
-    public function __construct(ContainerInterface $container)
+    protected $adminPool;
+
+    /**
+     * @param ContainerInterface|Pool $adminPool
+     */
+    public function __construct($adminPool)
     {
     {
-        $this->container = $container;
+        // NEXT_MAJOR : remove this block and set adminPool from parameter.
+        if ($adminPool instanceof ContainerInterface) {
+            @trigger_error(
+                'Using an instance of Symfony\Component\DependencyInjection\ContainerInterface is deprecated since 
+                version 3.x and will be removed in 4.0. Use Sonata\AdminBundle\Admin\Pool instead.',
+                E_USER_DEPRECATED
+            );
+
+            $this->adminPool = $adminPool->get('sonata.admin.pool');
+        } elseif ($adminPool instanceof Pool) {
+            $this->adminPool = $adminPool;
+        } else {
+            throw new \InvalidArgumentException(
+                '$adminPool should be an instance of Sonata\AdminBundle\Admin\Pool'
+            );
+        }
     }
     }
 
 
     /**
     /**
@@ -39,7 +60,7 @@ class GlobalVariables
      */
      */
     public function getAdminPool()
     public function getAdminPool()
     {
     {
-        return $this->container->get('sonata.admin.pool');
+        return $this->adminPool;
     }
     }
 
 
     /**
     /**

+ 4 - 0
UPGRADE-3.x.md

@@ -1,6 +1,10 @@
 UPGRADE 3.x
 UPGRADE 3.x
 ===========
 ===========
 
 
+## Deprecated injection of container to GlobalVariables
+
+The `$container` property in `Twig/GlobalVariables` is deprecated.
+
 ## Deprecated ModelTypeList for rename
 ## Deprecated ModelTypeList for rename
 
 
 The `Sonata\AdminBundle\Form\Type\ModelTypeList` class is now deprecated.
 The `Sonata\AdminBundle\Form\Type\ModelTypeList` class is now deprecated.