8000 Merge remote branch 'subsven/master' · lidaa/symfony@6daf09a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6daf09a

Browse files
committed
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
2 parents 6faacde + 4948666 commit 6daf09a

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
10000 -4
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
9090
->canBeUnset()
9191
->children()
9292
->booleanNode('only_exceptions')->defaultValue(false)->end()
93+
->booleanNode('only_master_requests')->defaultValue(false)->end()
9394
->scalarNode('dsn')->defaultValue('sqlite:%kernel.cache_dir%/profiler.db')->end()
9495
->scalarNode('username')->defaultValue('')->end()
9596
->scalarNode('password')->defaultValue('')->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
194194

195195
$container->getDefinition('profiler_listener')
196196
->setArgument(2, $config['only_exceptions'])
197+
->setArgument(3, $config['only_master_requests'])
197198
;
198199

199200
// Choose storage class based on the DSN

src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,25 @@
2727
class ProfilerListener
2828
{
2929
protected $container;
30-
protected $exception;
31-
protected $onlyException;
3230
protected $matcher;
31+
protected $onlyException;
32+
protected $onlyMasterRequests;
33+
protected $exception;
3334

3435
/**
3536
* Constructor.
3637
*
3738
* @param ContainerInterface $container A ContainerInterface instance
3839
* @param RequestMatcherInterface $matcher A RequestMatcher instance
3940
* @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise
41+
* @param Boolean $onlyMaster true if the profiler only collects data when the request is a master request, false otherwise
4042
*/
41-
public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false)
43+
public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false)
4244
{
4345
$this->container = $container;
4446
$this->matcher = $matcher;
45-
$this->onlyException = $onlyException;
47+
$this->onlyException = (Boolean) $onlyException;
48+
$this->onlyMasterRequests = (Boolean) $onlyMasterRequests;
4649
}
4750

4851
/**
@@ -81,6 +84,10 @@ public function onCoreResponse(FilterResponseEvent $event)
8184
{
8285
$response = $event->getResponse();
8386

87+
if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
88+
return $response;
89+
}
90+
8491
if (null !== $this->matcher && !$this->matcher->matches($event->getRequest())) {
8592
return $response;
8693
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<argument type="service" id="service_container" />
3131
<argument type="service" id="profiler.request_matcher" on-invalid="null" />
3232
<argument /> <!-- Only exceptions? -->
33+
<argument /> <!-- Only master requests? -->
3334
</service>
3435
</services>
3536
</container>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
</xsd:all>
5555

5656
<xsd:attribute name="only-exceptions" type="xsd:string" />
57+
<xsd:attribute name="only-master-requests" type="xsd:string" />
5758
<xsd:attribute name="dsn" type="xsd:string" />
5859
<xsd:attribute name="username" type="xsd:string" />
5960
<xsd:attribute name="password" type="xsd:string" />

0 commit comments

Comments
 (0)
0