瀏覽代碼

added priority support for normalizer order

Lukas Kahwe Smith 14 年之前
父節點
當前提交
fc08ac7c34
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      DependencyInjection/Compiler/RegisterNormalizersPass.php

+ 7 - 2
DependencyInjection/Compiler/RegisterNormalizersPass.php

@@ -32,9 +32,14 @@ class RegisterNormalizersPass implements CompilerPassInterface
         foreach ($container->findTaggedServiceIds('jms_serializer.normalizer') as $id => $attributes) {
             $def = $container->findDefinition($id);
             $strict = ContainerInterface::SCOPE_PROTOTYPE !== $def->getScope();
-            $normalizers[] = new Reference($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $strict);
+            $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
+            $normalizers[$priority][] = new Reference($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $strict);
         }
 
+        // sort by priority and flatten
+        krsort($normalizers);
+        $normalizers = call_user_func_array('array_merge', $normalizers);
+
         foreach (array_keys($container->findTaggedServiceIds('jms_serializer.serializer')) as $id) {
             $container
                 ->getDefinition($id)
@@ -42,4 +47,4 @@ class RegisterNormalizersPass implements CompilerPassInterface
             ;
         }
     }
-}
+}