moved KernelBundle logic to KernelExtension, and made test.xml decoupled from the error handler
The error_handler_level parameter (from kernel.config) has been renamed to error_handler (false to disable the error handler, null to catch errors from error_reporting(), and a number to catch more/less errors than error_reporting())
This commit is contained in:
parent
9452437c51
commit
2a8a9cc0a3
@ -3,13 +3,8 @@
|
||||
$container->setParameter('kernel.include_core_classes', false);
|
||||
|
||||
$container->loadFromExtension('kernel', 'config', array(
|
||||
'charset' => 'UTF-8',
|
||||
'error_handler_level' => null,
|
||||
));
|
||||
|
||||
$container->loadFromExtension('kernel', 'config', array(
|
||||
'charset' => 'UTF-8',
|
||||
'error_handler_level' => null,
|
||||
'charset' => 'UTF-8',
|
||||
'error_handler' => null,
|
||||
));
|
||||
|
||||
$container->loadFromExtension('web', 'config', array(
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
$loader->import('config_dev.php');
|
||||
|
||||
$container->loadFromExtension('kernel', 'config', array(
|
||||
'error_handler' => false,
|
||||
));
|
||||
|
||||
$container->loadFromExtension('web', 'config', array(
|
||||
'toolbar' => false,
|
||||
));
|
||||
|
@ -4,13 +4,11 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:swift="http://www.symfony-project.org/schema/dic/swiftmailer"
|
||||
xmlns:doctrine="http://www.symfony-project.org/schema/dic/doctrine"
|
||||
xmlns:symfony="http://www.symfony-project.org/schema/dic/symfony"
|
||||
xmlns:kernel="http://www.symfony-project.org/schema/dic/symfony/kernel"
|
||||
xmlns:zend="http://www.symfony-project.org/schema/dic/zend"
|
||||
xmlns:web="http://www.symfony-project.org/schema/dic/symfony"
|
||||
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd
|
||||
http://www.symfony-project.org/schema/dic/doctrine http://www.symfony-project.org/schema/dic/doctrine/doctrine-1.0.xsd
|
||||
http://www.symfony-project.org/schema/dic/symfony http://www.symfony-project.org/schema/dic/symfony/symfony-1.0.xsd
|
||||
http://www.symfony-project.org/schema/dic/swiftmailer http://www.symfony-project.org/schema/dic/swiftmailer/swiftmailer-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
@ -19,7 +17,7 @@
|
||||
|
||||
<kernel:config
|
||||
charset="UTF-8"
|
||||
error_handler_level="null"
|
||||
error_handler="null"
|
||||
/>
|
||||
|
||||
<web:config>
|
||||
|
@ -12,6 +12,10 @@
|
||||
<import resource="config_dev.xml" />
|
||||
</imports>
|
||||
|
||||
<kernel:config
|
||||
error_handler="false"
|
||||
/>
|
||||
|
||||
<web:config
|
||||
toolbar="false"
|
||||
/>
|
||||
|
@ -2,8 +2,8 @@ parameters:
|
||||
kernel.include_core_classes: false
|
||||
|
||||
kernel.config:
|
||||
charset: UTF-8
|
||||
error_handler_level: null
|
||||
charset: UTF-8
|
||||
error_handler: null
|
||||
|
||||
web.config:
|
||||
router: { resource: "%kernel.root_dir%/config/routing.yml" }
|
||||
|
@ -1,6 +1,9 @@
|
||||
imports:
|
||||
- { resource: config_dev.yml }
|
||||
|
||||
kernel.config:
|
||||
error_handler: false
|
||||
|
||||
zend.logger:
|
||||
priority: debug
|
||||
|
||||
|
@ -40,11 +40,9 @@ class ErrorHandler
|
||||
$this->level = null === $level ? error_reporting() : $level;
|
||||
}
|
||||
|
||||
public function register($enable=true)
|
||||
public function register()
|
||||
{
|
||||
if($enable) {
|
||||
set_error_handler(array($this, 'handle'));
|
||||
}
|
||||
set_error_handler(array($this, 'handle'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,22 +22,24 @@ use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||
*/
|
||||
class KernelExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* Loads the test configuration.
|
||||
*
|
||||
* @param array $config A configuration array
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*/
|
||||
public function testLoad($config, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||
$loader->load('test.xml');
|
||||
$container->setParameter('kernel.include_core_classes', false);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the session configuration.
|
||||
*
|
||||
* @param array $config A configuration array
|
||||
* @param array $config A configuration array
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @return ContainerBuilder A ContainerBuilder instance
|
||||
*/
|
||||
public function sessionLoad($config, ContainerBuilder $container)
|
||||
{
|
||||
@ -68,12 +70,26 @@ class KernelExtension extends Extension
|
||||
|
||||
$container->setParameter('session.session', 'session.session.'.strtolower($class));
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config configuration.
|
||||
*
|
||||
* @param array $config A configuration array
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*/
|
||||
public function configLoad($config, ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('event_dispatcher')) {
|
||||
$loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||
$loader->load('services.xml');
|
||||
|
||||
if ($container->getParameter('kernel.debug')) {
|
||||
$loader->load('debug.xml');
|
||||
$container->setDefinition('event_dispatcher', $container->findDefinition('debug.event_dispatcher'));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($config['charset'])) {
|
||||
$container->setParameter('kernel.charset', $config['charset']);
|
||||
}
|
||||
@ -112,11 +128,14 @@ class KernelExtension extends Extension
|
||||
}
|
||||
$container->setParameter('kernel.compiled_classes', $classes);
|
||||
|
||||
if (array_key_exists('error_handler_level', $config)) {
|
||||
$container->setParameter('error_handler.level', $config['error_handler_level']);
|
||||
if (array_key_exists('error_handler', $config)) {
|
||||
if (false === $config['error_handler']) {
|
||||
$container->getDefinition('error_handler')->setMethodCalls(array());
|
||||
} else {
|
||||
$container->getDefinition('error_handler')->addMethodCall('register', array());
|
||||
$container->setParameter('error_handler.level', $config['error_handler']);
|
||||
}
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,18 +37,6 @@ class KernelBundle extends Bundle
|
||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||
{
|
||||
ContainerBuilder::registerExtension(new KernelExtension());
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||
$loader->load('services.xml');
|
||||
|
||||
if ($parameterBag->get('kernel.debug')) {
|
||||
$loader->load('debug.xml');
|
||||
$container->setDefinition('event_dispatcher', $container->findDefinition('debug.event_dispatcher'));
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,10 +46,12 @@ class KernelBundle extends Bundle
|
||||
*/
|
||||
public function boot(ContainerInterface $container)
|
||||
{
|
||||
$container->getErrorHandlerService();
|
||||
if ($container->has('error_handler')) {
|
||||
$container['error_handler'];
|
||||
}
|
||||
|
||||
// load core classes
|
||||
if ($container->getParameter('kernel.include_core_classes')) {
|
||||
if ($container->getParameterBag()->has('kernel.include_core_classes') && $container->getParameter('kernel.include_core_classes')) {
|
||||
ClassCollectionLoader::load($container->getParameter('kernel.compiled_classes'), $container->getParameter('kernel.cache_dir'), 'classes', $container->getParameter('kernel.debug'));
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,6 @@
|
||||
|
||||
<service id="error_handler" class="%error_handler.class%">
|
||||
<argument>%error_handler.level%</argument>
|
||||
<call method="register">
|
||||
<argument>%error_handler.enable%</argument>
|
||||
</call>
|
||||
</service>
|
||||
|
||||
<service id="http_kernel" class="%http_kernel.class%">
|
||||
|
@ -9,7 +9,6 @@
|
||||
<parameter key="test.client.parameters" type="collection"></parameter>
|
||||
<parameter key="test.client.history.class">Symfony\Components\BrowserKit\History</parameter>
|
||||
<parameter key="test.client.cookiejar.class">Symfony\Components\BrowserKit\CookieJar</parameter>
|
||||
<parameter key="error_handler.enable">false</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Tests\Framework\Debug;
|
||||
|
||||
use Symfony\Framework\Debug\ErrorHandler;
|
||||
|
||||
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Symfony\Framework\Debug\ErrorHandler::register
|
||||
*/
|
||||
public function testRegister()
|
||||
{
|
||||
$fakeHandler = function($errno, $errstr)
|
||||
{
|
||||
die('Fake error handler triggered');
|
||||
};
|
||||
|
||||
$oldHandler = set_error_handler($fakeHandler);
|
||||
restore_error_handler();
|
||||
|
||||
$handler = new ErrorHandler();
|
||||
$handler->register(false);
|
||||
$newHandler = set_error_handler($fakeHandler);
|
||||
restore_error_handler();
|
||||
$this->assertEquals($oldHandler, $newHandler);
|
||||
|
||||
$handler = new ErrorHandler();
|
||||
$handler->register(true);
|
||||
$newHandler = set_error_handler($fakeHandler);
|
||||
restore_error_handler();
|
||||
$this->assertNotEquals($oldHandler, $newHandler);
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user