Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be3ec97

Browse files
committed
added some validation
1 parent c11a8eb commit be3ec97

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/Symfony/Bridge/Monolog/Handler/FingersCrossed/HttpCodeActivationStrategy.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ class HttpCodeActivationStrategy extends ErrorLevelActivationStrategy
2727

2828
public function __construct(RequestStack $requestStack, array $exclusions, $actionLevel)
2929
{
30+
foreach ($exclusions as $exclusion) {
31+
if (!array_key_exists('code', $exclusion)) {
32+
throw new \LogicException(sprintf('An exclusion must have a "code" key'));
33+
}
34+
if (!array_key_exists('urls', $exclusion)) {
35+
throw new \LogicException(sprintf('An exclusion must have a "urls" key'));
36+
}
37+
}
38+
3039
parent::__construct($actionLevel);
3140

3241
$this->requestStack = $requestStack;
@@ -49,8 +58,8 @@ public function isHandlerActivated(array $record)
4958
}
5059

5160
$urlBlacklist = null;
52-
if (count($exclusion['url'])) {
53-
return !preg_match('{('.implode('|', $exclusion['url']).')}i', $request->getPathInfo());
61+
if (count($exclusion['urls'])) {
62+
return !preg_match('{('.implode('|', $exclusion['urls']).')}i', $request->getPathInfo());
5463
}
5564

5665
return false;

src/Symfony/Bridge/Monolog/Tests/Handler/FingersCrossed/HttpCodeActivationStrategyTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public function testIsActivated($url, $record, $expected)
3131
$strategy = new HttpCodeActivationStrategy(
3232
$requestStack,
3333
array(
34-
array('code' => 403, 'url' => array()),
35-
array('code' => 404, 'url' => array()),
36-
array('code' => 405, 'url' => array()),
37-
array('code' => 400, 'url' => array('^/400/a', '^/400/b')),
34+
array('code' => 403, 'urls' => array()),
35+
array('code' => 404, 'urls' => array()),
36+
array('code' => 405, 'urls' => array()),
37+
array('code' => 400, 'urls' => array('^/400/a', '^/400/b')),
3838
),
3939
Logger::WARNING
4040
);

0 commit comments

Comments
 (0)