浏览代码

[FrameworkBundle] AddFormTypesPass now uses the service ID as alias if no alias is given

Bernhard Schussek 14 年之前
父节点
当前提交
9c4095a356
共有 1 个文件被更改,包括 9 次插入8 次删除
  1. 9 8
      src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFormTypesPass.php

+ 9 - 8
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFormTypesPass.php

@@ -29,16 +29,17 @@ class AddFormTypesPass implements CompilerPassInterface
         }
 
         // Builds an array with service IDs as keys and tag aliases as values
-        $types = array_map(function ($arguments) {
-            if (!isset($arguments[0]['alias'])) {
-                // TODO throw exception
-            }
+        $types = array();
+        $tags = $container->findTaggedServiceIds('form.type');
 
-            return $arguments[0]['alias'];
-        }, $container->findTaggedServiceIds('form.type'));
+        foreach ($tags as $serviceId => $arguments) {
+            $alias = isset($arguments[0]['alias'])
+                ? $arguments[0]['alias']
+                : $serviceId;
 
-        // Flip, because we want tag aliases (= type identifiers) as keys
-        $types = array_flip($types);
+            // Flip, because we want tag aliases (= type identifiers) as keys
+            $types[$alias] = $serviceId;
+        }
 
         $container->getDefinition('form.type.loader.tagged')->setArgument(1, $types);
     }