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

Skip to content

Commit 8115b0b

Browse files
committed
minor #14303 [Config][cache factory] check type of callback argument. (aitboudad)
This PR was merged into the 2.7 branch. Discussion ---------- [Config][cache factory] check type of callback argument. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | #14178 | Tests pass? | yes | License | MIT /cc @mpdude Commits ------- 11f798c [Config][cache factory] check type of callback argument.
2 parents 0ea25a9 + 11f798c commit 8115b0b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Symfony/Component/Config/ConfigCacheFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ public function __construct($debug)
3737
*/
3838
public function cache($file, $callback)
3939
{
40-
$cache = new ConfigCache($file, $this->debug);
40+
if (!is_callable($callback)) {
41+
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', gettype($callback)));
42+
}
4143

44+
$cache = new ConfigCache($file, $this->debug);
4245
if (!$cache->isFresh()) {
4346
call_user_func($callback, $cache);
4447
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Config\Tests;
13+
14+
use Symfony\Component\Config\ConfigCacheFactory;
15+
16+
class ConfigCacheFactoryTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @expectedException \InvalidArgumentException
20+
* @expectedExceptionMessage Invalid type for callback argument. Expected callable, but got "object".
21+
*/
22+
public function testCachWithInvalidCallback()
23+
{
24+
$cacheFactory = new ConfigCacheFactory(true);
25+
26+
$cacheFactory->cache('file', new \stdClass());
27+
}
28+
}

0 commit comments

Comments
 (0)