Bläddra i källkod

Fix deprecated getMetadataFactory method usage

Sullivan SENECHAL 10 år sedan
förälder
incheckning
baf9d425f6
2 ändrade filer med 13 tillägg och 3 borttagningar
  1. 6 1
      Admin/Admin.php
  2. 7 2
      Command/ExplainAdminCommand.php

+ 6 - 1
Admin/Admin.php

@@ -1359,7 +1359,12 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         $admin = $this;
 
         // add the custom inline validation option
-        $metadata = $this->validator->getMetadataFactory()->getMetadataFor($this->getClass());
+        // TODO: Remove conditional method when bumping requirements to SF 2.5+
+        if (method_exists($this->validator, 'getMetadataFor')) {
+            $metadata = $this->validator->getMetadataFor($this->getClass());
+        } else {
+            $metadata = $this->validator->getMetadataFactory()->getMetadataFor($this->getClass());
+        }
 
         $metadata->addConstraint(new InlineConstraint(array(
             'service' => $this,

+ 7 - 2
Command/ExplainAdminCommand.php

@@ -90,8 +90,13 @@ class ExplainAdminCommand extends ContainerAwareCommand
             $output->writeln(sprintf('  - % -25s  % -15s % -15s', $name, $fieldDescription->getType(), $fieldDescription->getTemplate()));
         }
 
-        $validatorFactory = $this->getContainer()->get('validator')->getMetadataFactory();
-        $metadata = $validatorFactory->getMetadataFor($admin->getClass());
+        $validator = $this->getContainer()->get('validator');
+        // TODO: Remove conditional method when bumping requirements to SF 2.5+
+        if (method_exists($validator, 'getMetadataFor')) {
+            $metadata = $validator->getMetadataFor($admin->getClass());
+        } else {
+            $metadata = $validator->getMetadataFactory()->getMetadataFor($admin->getClass());
+        }
 
         $output->writeln('');
         $output->writeln('<comment>Validation Framework</comment> - http://symfony.com/doc/2.0/book/validation.html');