Yaffs site version 1.1
[yaffs-website] / vendor / symfony / config / ResourceCheckerConfigCacheFactory.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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;
13
14 /**
15  * A ConfigCacheFactory implementation that validates the
16  * cache with an arbitrary set of ResourceCheckers.
17  *
18  * @author Matthias Pigulla <mp@webfactory.de>
19  */
20 class ResourceCheckerConfigCacheFactory implements ConfigCacheFactoryInterface
21 {
22     /**
23      * @var ResourceCheckerInterface[]
24      */
25     private $resourceCheckers = array();
26
27     /**
28      * @param ResourceCheckerInterface[] $resourceCheckers
29      */
30     public function __construct(array $resourceCheckers = array())
31     {
32         $this->resourceCheckers = $resourceCheckers;
33     }
34
35     /**
36      * {@inheritdoc}
37      */
38     public function cache($file, $callback)
39     {
40         if (!is_callable($callback)) {
41             throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', gettype($callback)));
42         }
43
44         $cache = new ResourceCheckerConfigCache($file, $this->resourceCheckers);
45         if (!$cache->isFresh()) {
46             call_user_func($callback, $cache);
47         }
48
49         return $cache;
50     }
51 }