Pārlūkot izejas kodu

[Form] AbstractType::getName() improvement

Brikou CARRE 14 gadi atpakaļ
vecāks
revīzija
28121e4a57

+ 1 - 5
src/Symfony/Component/Form/FormFactory.php

@@ -46,11 +46,7 @@ class FormFactory implements FormFactoryInterface
 
         // TESTME
         if (null === $name) {
-            $typeAsString = is_object($type) ? get_class($type) : $type;
-
-            if (preg_match('/\w+$/', $typeAsString, $matches)) {
-                $name = $matches[0];
-            }
+            $name = is_object($type) ? $type->getName() : $type;
         }
 
         while (null !== $type) {

+ 6 - 2
src/Symfony/Component/Form/Type/AbstractType.php

@@ -47,6 +47,10 @@ abstract class AbstractType implements FormTypeInterface
 
     public function getName()
     {
-        return get_class($this);
+        if (preg_match('/\\\\([a-z]+)(?:Form|Type)?$/im', get_class($this), $matches)) {
+            $name = strtolower($matches[1]);
+        }
+
+        return $name;
     }
-}
+}