Kaynağa Gözat

[FrameworkBundle] converted the special Profiler class to a DIC compiler class

Fabien Potencier 14 yıl önce
ebeveyn
işleme
2985cfa5a9

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

@@ -0,0 +1,37 @@
+<?php
+
+namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Adds tagged data_collector services to profiler service
+ *
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class ProfilerPass implements CompilerPassInterface
+{
+    public function process(ContainerBuilder $container)
+    {
+        if (false === $container->hasDefinition('profiler')) {
+            return;
+        }
+
+        $definition = $container->getDefinition('profiler');
+
+        foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
+            $definition->addMethodCall('add', array(new Reference($id)));
+        }
+    }
+}

+ 2 - 0
src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

@@ -5,6 +5,7 @@ namespace Symfony\Bundle\FrameworkBundle;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConverterManagerPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
+use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\HttpKernel\Bundle\Bundle;
 use Symfony\Component\Form\FormConfiguration;
@@ -46,5 +47,6 @@ class FrameworkBundle extends Bundle
         $container->addCompilerPass(new AddSecurityVotersPass());
         $container->addCompilerPass(new ConverterManagerPass());
         $container->addCompilerPass(new RoutingResolverPass());
+        $container->addCompilerPass(new ProfilerPass());
     }
 }

+ 0 - 34
src/Symfony/Bundle/FrameworkBundle/Profiler.php

@@ -1,34 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\FrameworkBundle;
-
-use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\HttpKernel\Profiler\Profiler as BaseProfiler;
-use Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface;
-use Symfony\Component\HttpKernel\Log\LoggerInterface;
-
-/*
- * This file is part of the Symfony framework.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-/**
- * Profiler.
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class Profiler extends BaseProfiler
-{
-    public function __construct(ContainerInterface $container, ProfilerStorageInterface $storage, LoggerInterface $logger = null)
-    {
-        parent::__construct($storage, $logger);
-
-        foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
-            $this->add($container->get($id));
-        }
-    }
-}

+ 1 - 2
src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml

@@ -5,7 +5,7 @@
     xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">
 
     <parameters>
-        <parameter key="profiler.class">Symfony\Bundle\FrameworkBundle\Profiler</parameter>
+        <parameter key="profiler.class">Symfony\Component\HttpKernel\Profiler\Profiler</parameter>
         <parameter key="profiler.storage.class">Symfony\Component\HttpKernel\Profiler\SQLiteProfilerStorage</parameter>
         <parameter key="profiler.storage.file">%kernel.cache_dir%/profiler.db</parameter>
         <parameter key="profiler.storage.lifetime">86400</parameter>
@@ -15,7 +15,6 @@
 
     <services>
         <service id="profiler" class="%profiler.class%">
-            <argument type="service" id="service_container" />
             <argument type="service" id="profiler.storage" />
             <argument type="service" id="logger" on-invalid="null" />
         </service>

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

@@ -31,7 +31,7 @@ class FrameworkExtensionTest extends TestCase
 
         // profiler
         $loader->configLoad(array('profiler' => true), $container);
-        $this->assertEquals('Symfony\\Bundle\\FrameworkBundle\\Profiler', $container->getParameter('profiler.class'), '->configLoad() loads the collectors.xml file if not already loaded');
+        $this->assertEquals('Symfony\Component\HttpKernel\Profiler\Profiler', $container->getParameter('profiler.class'), '->configLoad() loads the collectors.xml file if not already loaded');
 
         // templating
         $loader->configLoad(array('templating' => array()), $container);