diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php
index 328824d730..d4e1be5c31 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php
@@ -75,21 +75,7 @@ class WebExtension extends Extension
}
if (isset($config['profiler'])) {
- if ($config['profiler']) {
- if (!$container->hasDefinition('profiler')) {
- $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
- $loader->load('profiling.xml');
- $loader->load('collectors.xml');
- }
-
- if (isset($config['profiler']['only-exceptions'])) {
- $container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only-exceptions']);
- } elseif (isset($config['profiler']['only_exceptions'])) {
- $container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only_exceptions']);
- }
- } elseif ($container->hasDefinition('profiler')) {
- $container->getDefinition('profiling')->clearTags();
- }
+ $this->registerProfilerConfiguration($config, $container);
}
if (isset($config['validation']['enabled'])) {
@@ -204,6 +190,54 @@ class WebExtension extends Extension
));
}
+ /*
+
+
+
+
+
+
+
+ */
+ protected function registerProfilerConfiguration($config, ContainerBuilder $container)
+ {
+ if ($config['profiler']) {
+ if (!$container->hasDefinition('profiler')) {
+ $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
+ $loader->load('profiling.xml');
+ $loader->load('collectors.xml');
+ }
+
+ if (isset($config['profiler']['only-exceptions'])) {
+ $container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only-exceptions']);
+ } elseif (isset($config['profiler']['only_exceptions'])) {
+ $container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only_exceptions']);
+ }
+
+ if (isset($config['profiler']['matcher'])) {
+ if (isset($config['profiler']['matcher']['service'])) {
+ $container->setAlias('profiler.request_matcher', $config['profiler']['matcher']['service']);
+ } elseif (isset($config['profiler']['matcher']['_services'])) {
+ $container->setAlias('profiler.request_matcher', (string) $config['profiler']['matcher']['_services'][0]);
+ } else {
+ $definition = $container->register('profiler.request_matcher', 'Symfony\\Component\\HttpFoundation\\RequestMatcher');
+
+ if (isset($config['profiler']['matcher']['ip'])) {
+ $definition->addMethodCall('matchIp', array($config['profiler']['matcher']['ip']));
+ }
+
+ if (isset($config['profiler']['matcher']['path'])) {
+ $definition->addMethodCall('matchPath', array($config['profiler']['matcher']['path']));
+ }
+ }
+ } else {
+ $container->removeAlias('profiler.request_matcher');
+ }
+ } elseif ($container->hasDefinition('profiler')) {
+ $container->getDefinition('profiling')->clearTags();
+ }
+ }
+
protected function registerValidationConfiguration($config, ContainerBuilder $container)
{
if ($config['validation']['enabled']) {
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
index 22256b3622..0700231260 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
@@ -28,6 +28,7 @@
+
%profiler_listener.only_exceptions%
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
index b5c828a69e..83563e2d0f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
@@ -13,11 +13,22 @@
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
index 2d93970e4d..e8ebc07776 100644
--- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
+++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
@@ -38,7 +38,7 @@ class RequestDataCollector extends DataCollector
'request_server' => $request->server->all(),
'request_cookies' => $request->cookies->all(),
'response_headers' => $response->headers->all(),
- 'session_attributes' => $request->getSession()->getAttributes(),
+ 'session_attributes' => $request->hasSession() ? $request->getSession()->getAttributes() : array(),
);
}
diff --git a/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php b/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php
index 429bc9c2c6..4e36753077 100644
--- a/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php
+++ b/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php
@@ -6,6 +6,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpFoundation\RequestMatcherInterface;
/*
* This file is part of the Symfony framework.
@@ -26,16 +27,19 @@ class ProfilerListener
protected $profiler;
protected $exception;
protected $onlyException;
+ protected $matcher;
/**
* Constructor.
*
- * @param Profiler $profiler A Profiler instance
- * @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise
+ * @param Profiler $profiler A Profiler instance
+ * @param RequestMatcherInterface $matcher A RequestMatcher instance
+ * @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise
*/
- public function __construct(Profiler $profiler, $onlyException = false)
+ public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false)
{
$this->profiler = $profiler;
+ $this->matcher = $matcher;
$this->onlyException = $onlyException;
}
@@ -80,6 +84,10 @@ class ProfilerListener
return $response;
}
+ if (null !== $this->matcher && !$this->matcher->matches($event->getParameter('request'))) {
+ return $response;
+ }
+
if ($this->onlyException && null === $this->exception) {
return $response;
}
diff --git a/tests/Symfony/Tests/Component/HttpKernel/Profiler/ProfilerTest.php b/tests/Symfony/Tests/Component/HttpKernel/Profiler/ProfilerTest.php
index 6980d5cbca..352c2cf0d5 100644
--- a/tests/Symfony/Tests/Component/HttpKernel/Profiler/ProfilerTest.php
+++ b/tests/Symfony/Tests/Component/HttpKernel/Profiler/ProfilerTest.php
@@ -30,12 +30,12 @@ class ProfilerTest extends \PHPUnit_Framework_TestCase
$storage->purge(true);
$profiler = new Profiler($storage);
- $profiler->addCollector($collector);
+ $profiler->add($collector);
$profiler->setToken('foobar');
$profiler->collect($request, $response);
$profiler = new Profiler($storage);
$profiler->setToken('foobar');
- $this->assertEquals(array('foo' => 'bar'), $profiler->getCollector('request')->getRequestQuery()->all());
+ $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
}
}