ca3911ed5f9dc13bfb6d3c902d62bcfcbacb00e8
[yaffs-website] / vendor / symfony / http-kernel / CacheWarmer / CacheWarmerAggregate.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\HttpKernel\CacheWarmer;
13
14 /**
15  * Aggregates several cache warmers into a single one.
16  *
17  * @author Fabien Potencier <fabien@symfony.com>
18  *
19  * @final since version 3.4
20  */
21 class CacheWarmerAggregate implements CacheWarmerInterface
22 {
23     protected $warmers = array();
24     protected $optionalsEnabled = false;
25     private $triggerDeprecation = false;
26
27     public function __construct($warmers = array())
28     {
29         foreach ($warmers as $warmer) {
30             $this->add($warmer);
31         }
32         $this->triggerDeprecation = true;
33     }
34
35     public function enableOptionalWarmers()
36     {
37         $this->optionalsEnabled = true;
38     }
39
40     /**
41      * Warms up the cache.
42      *
43      * @param string $cacheDir The cache directory
44      */
45     public function warmUp($cacheDir)
46     {
47         foreach ($this->warmers as $warmer) {
48             if (!$this->optionalsEnabled && $warmer->isOptional()) {
49                 continue;
50             }
51
52             $warmer->warmUp($cacheDir);
53         }
54     }
55
56     /**
57      * Checks whether this warmer is optional or not.
58      *
59      * @return bool always false
60      */
61     public function isOptional()
62     {
63         return false;
64     }
65
66     /**
67      * @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
68      */
69     public function setWarmers(array $warmers)
70     {
71         @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
72
73         $this->warmers = array();
74         foreach ($warmers as $warmer) {
75             $this->add($warmer);
76         }
77     }
78
79     /**
80      * @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
81      */
82     public function add(CacheWarmerInterface $warmer)
83     {
84         if ($this->triggerDeprecation) {
85             @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
86         }
87
88         $this->warmers[] = $warmer;
89     }
90 }