comparison vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 class CacheWarmerAggregate implements CacheWarmerInterface
20 {
21 protected $warmers = array();
22 protected $optionalsEnabled = false;
23
24 public function __construct(array $warmers = array())
25 {
26 foreach ($warmers as $warmer) {
27 $this->add($warmer);
28 }
29 }
30
31 public function enableOptionalWarmers()
32 {
33 $this->optionalsEnabled = true;
34 }
35
36 /**
37 * Warms up the cache.
38 *
39 * @param string $cacheDir The cache directory
40 */
41 public function warmUp($cacheDir)
42 {
43 foreach ($this->warmers as $warmer) {
44 if (!$this->optionalsEnabled && $warmer->isOptional()) {
45 continue;
46 }
47
48 $warmer->warmUp($cacheDir);
49 }
50 }
51
52 /**
53 * Checks whether this warmer is optional or not.
54 *
55 * @return bool always false
56 */
57 public function isOptional()
58 {
59 return false;
60 }
61
62 public function setWarmers(array $warmers)
63 {
64 $this->warmers = array();
65 foreach ($warmers as $warmer) {
66 $this->add($warmer);
67 }
68 }
69
70 public function add(CacheWarmerInterface $warmer)
71 {
72 $this->warmers[] = $warmer;
73 }
74 }