1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Cache\Dependency; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Cache\CacheInterface; |
8
|
|
|
use Yiisoft\Cache\Exception\InvalidArgumentException; |
9
|
|
|
|
10
|
|
|
use function sprintf; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* AllDependencies represents a dependency which is composed of a list of other dependencies. |
14
|
|
|
* |
15
|
|
|
* The dependency is reported as changed if all sub-dependencies are changed. |
16
|
|
|
*/ |
17
|
|
|
final class AllDependencies extends Dependency |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Dependency[] |
21
|
|
|
*/ |
22
|
|
|
private array $dependencies; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param Dependency[] $dependencies list of dependencies that this dependency is composed of. |
26
|
|
|
* Each array element must be a dependency object. |
27
|
|
|
* |
28
|
|
|
* @psalm-suppress DocblockTypeContradiction, RedundantConditionGivenDocblockType |
29
|
|
|
*/ |
30
|
9 |
|
public function __construct(array $dependencies = []) |
31
|
|
|
{ |
32
|
9 |
|
foreach ($dependencies as $dependency) { |
33
|
9 |
|
if (!($dependency instanceof Dependency)) { |
34
|
8 |
|
throw new InvalidArgumentException(sprintf( |
35
|
|
|
'The dependency must be a "%s" instance, "%s" received', |
36
|
|
|
Dependency::class, |
37
|
8 |
|
get_debug_type($dependency), |
38
|
|
|
)); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
$this->dependencies = $dependencies; |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
public function evaluateDependency(CacheInterface $cache): void |
46
|
|
|
{ |
47
|
1 |
|
foreach ($this->dependencies as $dependency) { |
48
|
1 |
|
$dependency->evaluateDependency($cache); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @codeCoverageIgnore Method is not used. |
54
|
|
|
*/ |
55
|
|
|
protected function generateDependencyData(CacheInterface $cache): mixed |
56
|
|
|
{ |
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function isChanged(CacheInterface $cache): bool |
61
|
|
|
{ |
62
|
1 |
|
foreach ($this->dependencies as $dependency) { |
63
|
1 |
|
if (!$dependency->isChanged($cache)) { |
64
|
1 |
|
return false; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
return true; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|