ソースを参照

Avoided deprecation notice triggered by Sonata

The deprecation was always triggered, as Sonata calls the method. This
adds a flag argument to disable triggering the deprecation, a method
commonly used in Symfony to avoid unfixable deprecation notices.
WouterJ 8 年 前
コミット
567a20259e

+ 7 - 5
Admin/AbstractAdmin.php

@@ -2172,12 +2172,14 @@ EOT;
      *
      *
      * @deprecated since 3.9, to be removed with 4.0
      * @deprecated since 3.9, to be removed with 4.0
      */
      */
-    public function setTranslator(TranslatorInterface $translator)
+    public function setTranslator(TranslatorInterface $translator, $deprecation = true)
     {
     {
-        @trigger_error(
-            'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
-            E_USER_DEPRECATED
-        );
+        if ($deprecation) {
+            @trigger_error(
+                'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
+                E_USER_DEPRECATED
+            );
+        }
 
 
         $this->translator = $translator;
         $this->translator = $translator;
     }
     }

+ 6 - 1
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -275,7 +275,12 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
             $method = 'set'.Inflector::classify($attr);
             $method = 'set'.Inflector::classify($attr);
 
 
             if (isset($overwriteAdminConfiguration[$attr]) || !$definition->hasMethodCall($method)) {
             if (isset($overwriteAdminConfiguration[$attr]) || !$definition->hasMethodCall($method)) {
-                $definition->addMethodCall($method, array(new Reference(isset($overwriteAdminConfiguration[$attr]) ? $overwriteAdminConfiguration[$attr] : $addServiceId)));
+                $args = array(new Reference(isset($overwriteAdminConfiguration[$attr]) ? $overwriteAdminConfiguration[$attr] : $addServiceId));
+                if ('translator' === $attr) {
+                    $args[] = false;
+                }
+
+                $definition->addMethodCall($method, $args);
             }
             }
         }
         }