Skip to content

Commit

Permalink
bug #26874 [FrameworkBundle] Fixed configuration of php_errors.log (l…
Browse files Browse the repository at this point in the history
…yrixx)

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
  • Loading branch information
nicolas-grekas committed Apr 9, 2018
2 parents a726f05 + 8e0fcf9 commit 9a99955
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Expand Up @@ -889,13 +889,14 @@ private function addPhpErrorsSection(ArrayNodeDefinition $rootNode)
->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.')
Expand Down
Expand Up @@ -655,12 +655,10 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con

$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']) {
Expand Down
Expand Up @@ -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>
Expand Down
Expand Up @@ -340,23 +340,29 @@ public function testEnabledPhpErrorsConfig()
{
$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'));
}

public function testDisabledPhpErrorsConfig()
{
$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'));
}

public function testPhpErrorsWithLogLevel()
{
$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()
Expand Down

0 comments on commit 9a99955

Please sign in to comment.