From d06f805d9555da0e3c3d522a54e5f752b0e712f2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 17 Jan 2011 11:09:31 +0100 Subject: [PATCH] added a priority for data collectors --- .../Compiler/ProfilerPass.php | 16 +++++++++++++- .../Resources/config/collectors.xml | 16 +++++++------- .../Controller/ProfilerController.php | 21 +++++++++---------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php index b06243016c48..dc4c265484c5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php @@ -30,8 +30,22 @@ public function process(ContainerBuilder $container) $definition = $container->getDefinition('profiler'); + $collectors = array(); + $priorities = array(); + $templates = array(); foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) { - $definition->addMethodCall('add', array(new Reference($id))); + $priorities[] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0; + $collectors[] = $id; + if (isset($attributes[0]['template'])) { + $templates[] = $attributes[0]['template']; + } } + + array_multisort($priorities, SORT_DESC, $collectors, SORT_DESC, $templates); + foreach ($collectors as $collector) { + $definition->addMethodCall('add', array(new Reference($collector))); + } + + $container->setParameter('data_collector.templates', array_combine($collectors, $templates)); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml index 4a6c28e987f7..5f064023c1d9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml @@ -17,43 +17,43 @@ - + - + - + - + - + - + - + - + diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index e17a2476221c..04bca8a12dc5 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -241,18 +241,17 @@ public function searchAction() protected function getTemplateNames($profiler) { $templates = array(); - foreach ($this->container->findTaggedServiceIds('data_collector') as $id => $tags) { - if ($this->container->has($id) && isset($tags[0]['template'])) { - $name = $this->container->get($id)->getName(); - $template = $tags[0]['template']; - if ($profiler->has($name)) { - if (!$this->container->get('templating')->exists($template.'.twig.html')) { - continue; - } - - $templates[$name] = $template.'.twig.html'; - } + foreach ($this->container->getParameter('data_collector.templates') as $id => $template) { + if (!$this->container->has($id)) { + continue; } + + $name = $this->container->get($id)->getName(); + if (!$profiler->has($name) || !$this->container->get('templating')->exists($template.'.twig.html')) { + continue; + } + + $templates[$name] = $template.'.twig.html'; } return $templates;