Skip to content

Commit

Permalink
added a priority for data collectors
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 17, 2011
1 parent ca60259 commit d06f805
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
Expand Up @@ -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));
}
}
Expand Up @@ -17,43 +17,43 @@

<services>
<service id="data_collector.config" class="%data_collector.config.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:config" />
<tag name="data_collector" template="WebProfilerBundle:Collector:config" priority="255" />
<argument type="service" id="kernel" />
<argument type="service" id="router" on-invalid="ignore" />
</service>

<service id="data_collector.request" class="%data_collector.request.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:request" />
<tag name="data_collector" template="WebProfilerBundle:Collector:request" priority="250" />
</service>

<service id="data_collector.security" class="%data_collector.security.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:security" />
<tag name="data_collector" template="WebProfilerBundle:Collector:security" priority="245" />
<argument type="service" id="security.context" on-invalid="ignore" />
</service>

<service id="data_collector.exception" class="%data_collector.exception.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:exception" />
<tag name="data_collector" template="WebProfilerBundle:Collector:exception" priority="240" />
</service>

<service id="data_collector.events" class="%data_collector.events.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:events" />
<tag name="data_collector" template="WebProfilerBundle:Collector:events" priority="235" />
<call method="setEventDispatcher">
<argument type="service" id="event_dispatcher" />
</call>
</service>

<service id="data_collector.logger" class="%data_collector.logger.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:logger" />
<tag name="data_collector" template="WebProfilerBundle:Collector:logger" priority="230" />
<argument type="service" id="logger" on-invalid="ignore" />
</service>

<service id="data_collector.timer" class="%data_collector.timer.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:timer" />
<tag name="data_collector" template="WebProfilerBundle:Collector:timer" priority="225" />
<argument type="service" id="kernel" />
</service>

<service id="data_collector.memory" class="%data_collector.memory.class%">
<tag name="data_collector" template="WebProfilerBundle:Collector:memory" />
<tag name="data_collector" template="WebProfilerBundle:Collector:memory" priority="220" />
</service>
</services>
</container>
Expand Up @@ -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;
Expand Down

0 comments on commit d06f805

Please sign in to comment.