bug #26874 [FrameworkBundle] Fixed configuration of php_errors.log (lyrixx)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[FrameworkBundle] Fixed configuration of php_errors.log

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26504 and #26740 (wrong implementation)
| License       | MIT
| Doc PR        |

Commits
-------

8e0fcf9 [FrameworkBundle] Fixed configuration of php_errors.log
This commit is contained in:
Nicolas Grekas 2018-04-09 13:39:40 -05:00
commit 9a999553a5
4 changed files with 18 additions and 13 deletions

View File

@ -889,13 +889,14 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->scalarNode('log')
->info('Use the app logger instead of the PHP logger for logging PHP errors.')
->info('Use the application logger instead of the PHP logger for logging PHP errors.')
->example('"true" to use the default configuration: log all errors. "false" to disable. An integer bit field of E_* constants.')
->defaultValue($this->debug)
->treatNullLike($this->debug)
->validate()
->ifTrue(function ($v) { return !(\is_int($v) || \is_bool($v)); })
->thenInvalid('The "php_errors.log" parameter should be either an integer or a boolean.')
->end()
->ifTrue(function ($v) { return !(\is_int($v) || \is_bool($v)); })
->thenInvalid('The "php_errors.log" parameter should be either an integer or a boolean.')
->end()
->end()
->booleanNode('throw')
->info('Throw PHP errors as \ErrorException instances.')

View File

@ -655,12 +655,10 @@ class FrameworkExtension extends Extension
$definition = $container->findDefinition('debug.debug_handlers_listener');
if (!$config['log']) {
if (false === $config['log']) {
$definition->replaceArgument(1, null);
}
if (\is_int($config['log']) && $config['log']) {
$definition->replaceArgument(3, $config['log']);
} elseif (true !== $config['log']) {
$definition->replaceArgument(2, $config['log']);
}
if (!$config['throw']) {

View File

@ -16,7 +16,7 @@
<tag name="monolog.logger" channel="php" />
<argument>null</argument><!-- Exception handler -->
<argument type="service" id="logger" on-invalid="null" />
<argument>-1</argument><!-- Log levels map for enabled error levels -->
<argument>null</argument><!-- Log levels map for enabled error levels -->
<argument>%debug.error_handler.throw_at%</argument>
<argument>true</argument>
<argument type="service" id="debug.file_link_formatter"></argument>

View File

@ -340,7 +340,9 @@ abstract class FrameworkExtensionTest extends TestCase
{
$container = $this->createContainerFromFile('php_errors_enabled');
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $container->getDefinition('debug.debug_handlers_listener')->getArgument(1));
$definition = $container->getDefinition('debug.debug_handlers_listener');
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
$this->assertNull($definition->getArgument(2));
$this->assertSame(-1, $container->getParameter('debug.error_handler.throw_at'));
}
@ -348,7 +350,9 @@ abstract class FrameworkExtensionTest extends TestCase
{
$container = $this->createContainerFromFile('php_errors_disabled');
$this->assertNull($container->getDefinition('debug.debug_handlers_listener')->getArgument(1));
$definition = $container->getDefinition('debug.debug_handlers_listener');
$this->assertNull($definition->getArgument(1));
$this->assertNull($definition->getArgument(2));
$this->assertSame(0, $container->getParameter('debug.error_handler.throw_at'));
}
@ -356,7 +360,9 @@ abstract class FrameworkExtensionTest extends TestCase
{
$container = $this->createContainerFromFile('php_errors_log_level');
$this->assertEquals(8, $container->getDefinition('debug.debug_handlers_listener')->getArgument(3));
$definition = $container->getDefinition('debug.debug_handlers_listener');
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
$this->assertSame(8, $definition->getArgument(2));
}
public function testRouter()