Преглед на файлове

made order of template engine and data collector more predictable

Fabien Potencier преди 14 години
родител
ревизия
15575bccc4

+ 11 - 11
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php

@@ -30,24 +30,24 @@ class ProfilerPass implements CompilerPassInterface
 
         $definition = $container->getDefinition('profiler');
 
-        $collectors = array();
-        $priorities = array();
-        $templates = array();
+        $collectors = new \SplPriorityQueue();
+        $order = PHP_INT_MAX;
         foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
-            $priorities[] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
-            $collectors[] = $id;
+            $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
+            $template = null;
             if (isset($attributes[0]['template']) && isset($attributes[0]['id'])) {
-                $templates[] = array($attributes[0]['id'], $attributes[0]['template']);
-            } else {
-                $templates[] = null;
+                $template = array($attributes[0]['id'], $attributes[0]['template']);
             }
+
+            $collectors->insert(array($id, $template), array($priority, --$order));
         }
 
-        array_multisort($priorities, SORT_DESC, $collectors, SORT_DESC, $templates);
+        $templates = array();
         foreach ($collectors as $collector) {
-            $definition->addMethodCall('add', array(new Reference($collector)));
+            $definition->addMethodCall('add', array(new Reference($collector[0])));
+            $templates[$collector[0]] = $collector[1];
         }
 
-        $container->setParameter('data_collector.templates', array_combine($collectors, $templates));
+        $container->setParameter('data_collector.templates', $templates);
     }
 }

+ 2 - 1
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TemplatingPass.php

@@ -33,8 +33,9 @@ class TemplatingPass implements CompilerPassInterface
 
         if ($container->hasDefinition('templating.engine.delegating')) {
             $queue = new \SplPriorityQueue();
+            $order = PHP_INT_MAX;
             foreach ($container->findTaggedServiceIds('templating.engine') as $id => $attributes) {
-                $queue->insert($id, isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0);
+                $queue->insert($id, array(isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0, --$order));
             }
 
             $engines = array();

+ 7 - 7
src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml

@@ -23,37 +23,37 @@
         </service>
 
         <service id="data_collector.request" class="%data_collector.request.class%" public="false">
-            <tag name="data_collector" template="WebProfilerBundle:Collector:request" id="request" priority="250" />
+            <tag name="data_collector" template="WebProfilerBundle:Collector:request" id="request" priority="255" />
         </service>
 
         <service id="data_collector.security" class="%data_collector.security.class%" public="false">
-            <tag name="data_collector" template="WebProfilerBundle:Collector:security" id="security" priority="245" />
+            <tag name="data_collector" template="WebProfilerBundle:Collector:security" id="security" priority="255" />
             <argument type="service" id="security.context" on-invalid="ignore" />
         </service>
 
         <service id="data_collector.exception" class="%data_collector.exception.class%" public="false">
-            <tag name="data_collector" template="WebProfilerBundle:Collector:exception" id="exception" priority="240" />
+            <tag name="data_collector" template="WebProfilerBundle:Collector:exception" id="exception" priority="255" />
         </service>
 
         <service id="data_collector.events" class="%data_collector.events.class%" public="false">
-            <tag name="data_collector" template="WebProfilerBundle:Collector:events" id="events" priority="235" />
+            <tag name="data_collector" template="WebProfilerBundle:Collector:events" id="events" priority="255" />
             <call method="setEventDispatcher">
                 <argument type="service" id="event_dispatcher" />
             </call>
         </service>
 
         <service id="data_collector.logger" class="%data_collector.logger.class%" public="false">
-            <tag name="data_collector" template="WebProfilerBundle:Collector:logger" id="logger" priority="230" />
+            <tag name="data_collector" template="WebProfilerBundle:Collector:logger" id="logger" priority="255" />
             <argument type="service" id="logger" on-invalid="ignore" />
         </service>
 
         <service id="data_collector.timer" class="%data_collector.timer.class%" public="false">
-            <tag name="data_collector" template="WebProfilerBundle:Collector:timer" id="timer" priority="225" />
+            <tag name="data_collector" template="WebProfilerBundle:Collector:timer" id="timer" priority="255" />
             <argument type="service" id="kernel" />
         </service>
 
         <service id="data_collector.memory" class="%data_collector.memory.class%" public="false">
-            <tag name="data_collector" template="WebProfilerBundle:Collector:memory" id="memory" priority="220" />
+            <tag name="data_collector" template="WebProfilerBundle:Collector:memory" id="memory" priority="255" />
         </service>
     </services>
 </container>