Permalink
Browse files

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
  • Loading branch information...
2 parents 6faacde + 4948666 commit 6daf09a61d3970b40941d1407ecdb25161d777d6 @fabpot fabpot committed Apr 5, 2011
@@ -90,6 +90,7 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
->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()
@@ -194,6 +194,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
$container->getDefinition('profiler_listener')
->setArgument(2, $config['only_exceptions'])
+ ->setArgument(3, $config['only_master_requests'])
;
// Choose storage class based on the DSN
@@ -27,22 +27,25 @@
class ProfilerListener
{
protected $container;
- protected $exception;
- protected $onlyException;
protected $matcher;
+ protected $onlyException;
+ protected $onlyMasterRequests;
+ protected $exception;
/**
* Constructor.
*
* @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 @@ public function onCoreResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
+ if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+ return $response;
+ }
+
if (null !== $this->matcher && !$this->matcher->matches($event->getRequest())) {
return $response;
}
@@ -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>
@@ -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" />

0 comments on commit 6daf09a

Please sign in to comment.