Skip to content

Commit 30a70a2

Browse files
committed
tweaked code
1 parent 61a78a6 commit 30a70a2

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

DependencyInjection/Configuration.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
* - handler: the wrapped handler's name
9090
* - [action_level|activation_strategy]: minimum level or service id to activate the handler, defaults to WARNING
9191
* - [excluded_404s]: if set, the strategy will be changed to one that excludes 404s coming from URLs matching any of those patterns
92-
* - [excluded_http_codes]: if set, the strategy will be changed to one that excludes specific HTTP codes
92+
* - [excluded_http_codes]: if set, the strategy will be changed to one that excludes specific HTTP codes (requires Symfony Monolog bridge 4.1+)
9393
* - [buffer_size]: defaults to 0 (unlimited)
9494
* - [stop_buffering]: bool to disable buffering once the handler has been activated, defaults to true
9595
* - [passthru_level]: level name or int value for messages to always flush, disabled by default
@@ -383,19 +383,17 @@ public function getConfigTreeBuilder()
383383
*/
384384

385385
if (is_array($value)) {
386-
return isset($value['code'])
387-
? $value
388-
: array('code' => key($value), 'url' => current($value));
386+
return isset($value['code']) ? $value : array('code' => key($value), 'urls' => current($value));
389387
}
390388

391-
return array('code' => $value, 'url' => array());
389+
return array('code' => $value, 'urls' => array());
392390
}, $values);
393391
})
394392
->end()
395393
->prototype('array')
396394
->children()
397395
->scalarNode('code')->end()
398-
->arrayNode('url')
396+
->arrayNode('urls')
399397
->prototype('scalar')->end()
400398
->end()
401399
->end()

DependencyInjection/MonologExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
325325
$container->setDefinition($handlerId.'.not_found_strategy', $activationDef);
326326
$activation = new Reference($handlerId.'.not_found_strategy');
327327
} elseif (!empty($handler['excluded_http_codes'])) {
328+
if (!class_exists('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy')) {
329+
throw new \LogicException('"excluded_http_codes" cannot be used as your version of Monolog bridge does not support it.');
330+
}
328331
$activationDef = new Definition('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy', array(
329332
new Reference('request_stack'),
330333
$handler['excluded_http_codes'],

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ public function testFingersCrossedHandlerWhenExcluded404sAreSpecified()
385385

386386
public function testFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified()
387387
{
388+
if (!class_exists('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy')) {
389+
$this->markTestSkipped('Symfony Monolog 4.1+ is needed.');
390+
}
391+
388392
$container = $this->getContainer(array(array('handlers' => array(
389393
'main' => array(
390394
'type' => 'fingers_crossed',
@@ -408,9 +412,9 @@ public function testFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified()
408412
$this->assertDICConstructorArguments($strategy, array(
409413
new Reference('request_stack'),
410414
array(
411-
array('code' => 403, 'url' => array()),
412-
array('code' => 404, 'url' => array()),
413-
array('code' => 405, 'url' => array('^/foo', '^/bar'))
415+
array('code' => 403, 'urls' => array()),
416+
array('code' => 404, 'urls' => array()),
417+
array('code' => 405, 'urls' => array('^/foo', '^/bar'))
414418
),
415419
\Monolog\Logger::WARNING
416420
));

0 commit comments

Comments
 (0)