yii2

Форк
1
/
ChainedDependency.php 
75 строк · 2.5 Кб
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7

8
namespace yii\caching;
9

10
/**
11
 * ChainedDependency represents a dependency which is composed of a list of other dependencies.
12
 *
13
 * When [[dependOnAll]] is true, if any of the dependencies has changed, this dependency is
14
 * considered changed; When [[dependOnAll]] is false, if one of the dependencies has NOT changed,
15
 * this dependency is considered NOT changed.
16
 *
17
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
18
 *
19
 * @author Qiang Xue <qiang.xue@gmail.com>
20
 * @since 2.0
21
 */
22
class ChainedDependency extends Dependency
23
{
24
    /**
25
     * @var Dependency[] list of dependencies that this dependency is composed of.
26
     * Each array element must be a dependency object.
27
     */
28
    public $dependencies = [];
29
    /**
30
     * @var bool whether this dependency is depending on every dependency in [[dependencies]].
31
     * Defaults to true, meaning if any of the dependencies has changed, this dependency is considered changed.
32
     * When it is set false, it means if one of the dependencies has NOT changed, this dependency
33
     * is considered NOT changed.
34
     */
35
    public $dependOnAll = true;
36

37

38
    /**
39
     * Evaluates the dependency by generating and saving the data related with dependency.
40
     * @param CacheInterface $cache the cache component that is currently evaluating this dependency
41
     */
42
    public function evaluateDependency($cache)
43
    {
44
        foreach ($this->dependencies as $dependency) {
45
            $dependency->evaluateDependency($cache);
46
        }
47
    }
48

49
    /**
50
     * Generates the data needed to determine if dependency has been changed.
51
     * This method does nothing in this class.
52
     * @param CacheInterface $cache the cache component that is currently evaluating this dependency
53
     * @return mixed the data needed to determine if dependency has been changed.
54
     */
55
    protected function generateDependencyData($cache)
56
    {
57
        return null;
58
    }
59

60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function isChanged($cache)
64
    {
65
        foreach ($this->dependencies as $dependency) {
66
            if ($this->dependOnAll && $dependency->isChanged($cache)) {
67
                return true;
68
            } elseif (!$this->dependOnAll && !$dependency->isChanged($cache)) {
69
                return false;
70
            }
71
        }
72

73
        return !$this->dependOnAll;
74
    }
75
}
76

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.