vendor/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     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  *
       
    16  * @author Fabien Potencier <fabien@symfony.com>
       
    17  */
       
    18 class CacheWarmerAggregate implements CacheWarmerInterface
       
    19 {
       
    20     protected $warmers;
       
    21     protected $optionalsEnabled;
       
    22 
       
    23     public function __construct(array $warmers = array())
       
    24     {
       
    25         $this->setWarmers($warmers);
       
    26         $this->optionalsEnabled = false;
       
    27     }
       
    28 
       
    29     public function enableOptionalWarmers()
       
    30     {
       
    31         $this->optionalsEnabled = true;
       
    32     }
       
    33 
       
    34     /**
       
    35      * Warms up the cache.
       
    36      *
       
    37      * @param string $cacheDir The cache directory
       
    38      */
       
    39     public function warmUp($cacheDir)
       
    40     {
       
    41         foreach ($this->warmers as $warmer) {
       
    42             if (!$this->optionalsEnabled && $warmer->isOptional()) {
       
    43                 continue;
       
    44             }
       
    45 
       
    46             $warmer->warmUp($cacheDir);
       
    47         }
       
    48     }
       
    49 
       
    50     /**
       
    51      * Checks whether this warmer is optional or not.
       
    52      *
       
    53      * @return Boolean always true
       
    54      */
       
    55     public function isOptional()
       
    56     {
       
    57         return false;
       
    58     }
       
    59 
       
    60     public function setWarmers(array $warmers)
       
    61     {
       
    62         $this->warmers = array();
       
    63         foreach ($warmers as $warmer) {
       
    64             $this->add($warmer);
       
    65         }
       
    66     }
       
    67 
       
    68     public function add(CacheWarmerInterface $warmer)
       
    69     {
       
    70         $this->warmers[] = $warmer;
       
    71     }
       
    72 }