/
MultipleCondition.php
69 lines (60 loc) 路 1.37 KB
/
MultipleCondition.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @package WPEmerge
* @author Atanas Angelov <hi@atanas.dev>
* @copyright 2017-2019 Atanas Angelov
* @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
* @link https://wpemerge.com/
*/
namespace WPEmerge\Routing\Conditions;
use WPEmerge\Requests\RequestInterface;
/**
* Check against an array of conditions in an AND logical relationship.
*/
class MultipleCondition implements ConditionInterface {
/**
* Array of conditions to check.
*
* @var ConditionInterface[]
*/
protected $conditions = [];
/**
* Constructor.
*
* @codeCoverageIgnore
* @param ConditionInterface[] $conditions
*/
public function __construct( $conditions ) {
$this->conditions = $conditions;
}
/**
* Get all assigned conditions
*
* @codeCoverageIgnore
* @return ConditionInterface[]
*/
public function getConditions() {
return $this->conditions;
}
/**
* {@inheritDoc}
*/
public function isSatisfied( RequestInterface $request ) {
foreach ( $this->conditions as $condition ) {
if ( ! $condition->isSatisfied( $request ) ) {
return false;
}
}
return true;
}
/**
* {@inheritDoc}
*/
public function getArguments( RequestInterface $request ) {
$arguments = [];
foreach ( $this->conditions as $condition ) {
$arguments = array_merge( $arguments, $condition->getArguments( $request ) );
}
return $arguments;
}
}