Переглянути джерело

Merge remote branch 'subsven/master'

* subsven/master:
  Add (Boolean) cast to constructor arguments
  Add a configuration option to restrict profiler storage to the master request
Fabien Potencier 14 роки тому
батько
коміт
6daf09a61d

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

@@ -90,6 +90,7 @@ class Configuration
                     ->canBeUnset()
                     ->children()
                         ->booleanNode('only_exceptions')->defaultValue(false)->end()
+                        ->booleanNode('only_master_requests')->defaultValue(false)->end()
                         ->scalarNode('dsn')->defaultValue('sqlite:%kernel.cache_dir%/profiler.db')->end()
                         ->scalarNode('username')->defaultValue('')->end()
                         ->scalarNode('password')->defaultValue('')->end()

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

@@ -194,6 +194,7 @@ class FrameworkExtension extends Extension
 
         $container->getDefinition('profiler_listener')
             ->setArgument(2, $config['only_exceptions'])
+            ->setArgument(3, $config['only_master_requests'])
         ;
 
         // Choose storage class based on the DSN

+ 11 - 4
src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php

@@ -27,9 +27,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 class ProfilerListener
 {
     protected $container;
-    protected $exception;
-    protected $onlyException;
     protected $matcher;
+    protected $onlyException;
+    protected $onlyMasterRequests;
+    protected $exception;
 
     /**
      * Constructor.
@@ -37,12 +38,14 @@ class ProfilerListener
      * @param ContainerInterface      $container     A ContainerInterface instance
      * @param RequestMatcherInterface $matcher       A RequestMatcher instance
      * @param Boolean                 $onlyException true if the profiler only collects data when an exception occurs, false otherwise
+     * @param Boolean                 $onlyMaster    true if the profiler only collects data when the request is a master request, false otherwise
      */
-    public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false)
+    public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false)
     {
         $this->container = $container;
         $this->matcher = $matcher;
-        $this->onlyException = $onlyException;
+        $this->onlyException = (Boolean) $onlyException;
+        $this->onlyMasterRequests = (Boolean) $onlyMasterRequests;
     }
 
     /**
@@ -81,6 +84,10 @@ class ProfilerListener
     {
         $response = $event->getResponse();
 
+        if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+            return $response;
+        }
+
         if (null !== $this->matcher && !$this->matcher->matches($event->getRequest())) {
             return $response;
         }

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

@@ -30,6 +30,7 @@
             <argument type="service" id="service_container" />
             <argument type="service" id="profiler.request_matcher" on-invalid="null" />
             <argument /> <!-- Only exceptions? -->
+            <argument /> <!-- Only master requests? -->
         </service>
     </services>
 </container>

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

@@ -54,6 +54,7 @@
         </xsd:all>
 
         <xsd:attribute name="only-exceptions" type="xsd:string" />
+        <xsd:attribute name="only-master-requests" type="xsd:string" />
         <xsd:attribute name="dsn" type="xsd:string" />
         <xsd:attribute name="username" type="xsd:string" />
         <xsd:attribute name="password" type="xsd:string" />