Skip to content

Commit 3ca9d71

Browse files
committed
[Config][cache factory] check type of callback argument.
1 parent 1ba2d20 commit 3ca9d71

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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
}

Tests/ConfigCacheFactoryTest.php

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)