8000 [FrameworkBundle] Don't load the profiler when it is disabled by dlsniper · Pull Request #7071 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Don't load the profiler when it is disabled #7071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerValidationConfiguration($config['validation'], $container, $loader);
$this->registerEsiConfiguration($config['esi'], $container, $loader);
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);

if (isset($config['profiler']) && isset($config['profiler']['enabled']) && $config['profiler']['enabled']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First isset is unnecessary, isn't it?

$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
}

$this->registerTranslatorConfiguration($config['translator'], $container);

if (isset($config['router'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
),
'profiler' => array(
'only_exceptions' => true,
'enabled' => false,
),
'router' => array(
'resource' => '%kernel.root_dir%/config/routing.xml',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

$container->loadFromExtension('framework', array(
'secret' => 's3cr3t',
'default_locale' => 'fr',
'form' => null,
'trust_proxy_headers' => true,
'trusted_proxies' => array('127.0.0.1', '10.0.0.1'),
'csrf_protection' => array(
'enabled' => true,
'field_name' => '_csrf',
),
'esi' => array(
'enabled' => true,
),
'profiler' => array(
'only_exceptions' => true,
'enabled' => false,
),
'router' => array(
'resource' => '%kernel.root_dir%/config/routing.xml',
'type' => 'xml',
),
'session' => array(
'storage_id' => 'session.storage.native',
'handler_id' => 'session.handler.native_file',
'name' => '_SYMFONY',
'lifetime' => 86400,
'path' => '/',
'domain' => 'example.com',
'secure' => true,
'httponly' => true,
'gc_maxlifetime' => 90000,
'gc_divisor' => 108,
'gc_probability' => 1,
'save_path' => '/path/to/sessions',
),
'templating' => array(
'assets_version' => 'SomeVersionScheme',
'assets_base_urls' => 'http://cdn.example.com',
'cache' => '/path/to/cache',
'engines' => array('php', 'twig'),
'loader' => array('loader.foo', 'loader.bar'),
'packages' => array(
'images' => array(
'version' => '1.0.0',
'base_urls' => array('http://images1.example.com', 'http://images2.example.com'),
),
'foo' => array(
'version' => '1.0.0',
),
'bar' => array(
'base_urls' => array('http://bar1.example.com', 'http://bar2.example.com'),
),
),
'form' => array(
'resources' => array('theme1', 'theme2')
),
),
'translator' => array(
'enabled' => true,
'fallback' => 'fr',
),
'validation' => array(
'enabled' => true,
'cache' => 'apc',
),
'annotations' => array(
'cache' => 'file',
'debug' => true,
'file_cache_dir' => '%kernel.cache_dir%/annotations',
),
'ide' => 'file%%link%%format'
));
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<framework:csrf-protection enabled="true" field-name="_csrf" />
<framework:form />
<framework:esi enabled="true" />
<framework:profiler only-exceptions="true" enabled="false" />
<framework:profiler only-exceptions="true" />
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" save-path="/path/to/sessions" />
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" trust-proxy-headers="true" trusted-proxies="127.0.0.1, 10.0.0.1">
<framework:csrf-protection enabled="true" field-name="_csrf" />
<framework:form />
<framework:esi enabled="true" />
<framework:profiler only-exceptions="true" enabled="false" />
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" save-path="/path/to/sessions" />
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
<framework:loader>loader.foo</framework:loader>
<framework:loader>loader.bar</framework:loader>
<framework:engine>php</framework:engine>
<framework:engine>twig</framework:engine>
<framework:assets-base-url>http://cdn.example.com</framework:assets-base-url>
<framework:package name="images" version="1.0.0">
<framework:base-url>http://images1.example.com</framework:base-url>
<framework:base-url>http://images2.example.com</framework:base-url>
</framework:package>
<framework:package name="foo" version="1.0.0" />
<framework:package name="bar">
<framework:base-url>http://bar1.example.com</framework:base-url>
<framework:base-url>http://bar2.example.com</framework:base-url>
</framework:package>
<framework:form>
<framework:resource>theme1</framework:resource>
<framework:resource>theme2</framework:resource>
</framework:form>
</framework:templating>
<framework:translator enabled="true" fallback="fr" />
<framework:validation enabled="true" cache="apc" />
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
</framework:config>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ framework:
enabled: true
profiler:
only_exceptions: true
enabled: false
router:
resource: %kernel.root_dir%/config/routing.xml
type: xml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
framework:
secret: s3cr3t
default_locale: fr
form: ~
trust_proxy_headers: true
trusted_proxies: ['127.0.0.1', '10.0.0.1']
csrf_protection:
enabled: true
field_name: _csrf
esi:
enabled: true
profiler:
only_exceptions: true
enabled: false
router:
resource: %kernel.root_dir%/config/routing.xml
type: xml
session:
storage_id: session.storage.native
handler_id: session.handler.native_file
name: _SYMFONY
lifetime: 86400
path: /
domain: example.com
secure: true
httponly: true
gc_probability: 1
gc_divisor: 108
gc_maxlifetime: 90000
save_path: /path/to/sessions
templating:
assets_version: SomeVersionScheme
assets_base_urls: http://cdn.example.com
engines: [php, twig]
loader: [loader.foo, loader.bar]
cache: /path/to/cache
packages:
images:
version: 1.0.0
base_urls: ["http://images1.example.com", "http://images2.example.com"]
foo:
version: 1.0.0
bar:
base_urls: ["http://images1.example.com", "http://images2.example.com"]
form:
resources: [theme1, theme2]
translator:
enabled: true
fallback: fr
validation:
enabled: true
cache: apc
annotations:
cache: file
debug: true
file_cache_dir: %kernel.cache_dir%/annotations
ide: file%%link%%format
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ public function testProfiler()
$this->assertTrue($container->hasDefinition('data_collector.config'), '->registerProfilerConfiguration() loads collectors.xml');
$this->assertTrue($container->getParameter('profiler_listener.only_exceptions'));
$this->assertEquals('%profiler_listener.only_exceptions%', $container->getDefinition('profiler_listener')->getArgument(2));
}

public function testDisabledProfiler()
{
$container = $this->createContainerFromFile('full_disabled');

$calls = $container->getDefinition('profiler')->getMethodCalls();
$this->assertEquals('disable', $calls[0][0]);
$this->assertFalse($container->hasDefinition('profiler'), '->registerProfilerConfiguration() does not load profiling.xml');
$this->assertFalse($container->hasDefinition('data_collector.config'), '->registerProfilerConfiguration() does not load collectors.xml');
$this->assertFalse($container->hasParameter('profiler_listener.only_exceptions'));
}

public function testRouter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testProfilerIsDisabled($insulate)
$client->enableProfiler();
$crawler = $client->request('GET', '/profiler');
$profile = $client->getProfile();
$this->assertTrue(is_object($profile));
$this->assertFalse(is_object($profile));

$client->request('GET', '/profiler');
$this->assertFalse($client->getProfile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class WebProfilerExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
if (!$container->hasParameter('profiler.class')) {
return;
}

$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected function setUp()
$this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.debug', false);
$this->container->setParameter('kernel.root_dir', __DIR__);
$this->container->setParameter('profiler.class', array('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'));
$this->container->register('profiler', $this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'))
->addArgument(new Definition($this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\ProfilerStorageInterface')));
$this->container->setParameter('data_collector.templates', array());
Expand Down
0