|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package WPEmerge |
|
4
|
|
|
* @author Atanas Angelov <[email protected]> |
|
5
|
|
|
* @copyright 2018 Atanas Angelov |
|
6
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 |
|
7
|
|
|
* @link https://wpemerge.com/ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace WPEmerge\Routing\Conditions; |
|
11
|
|
|
|
|
12
|
|
|
use WPEmerge\Facades\RouteCondition; |
|
13
|
|
|
use WPEmerge\Requests\RequestInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Negate another condition's result. |
|
17
|
|
|
* |
|
18
|
|
|
* @codeCoverageIgnore |
|
19
|
|
|
*/ |
|
20
|
|
|
class NegateCondition implements ConditionInterface, HasUrlInterface { |
|
21
|
|
|
/** |
|
22
|
|
|
* Condition to negate. |
|
23
|
|
|
* |
|
24
|
|
|
* @var ConditionInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $condition = null; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param mixed $condition |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct( $condition ) { |
|
34
|
|
|
if ( $condition instanceof ConditionInterface ) { |
|
35
|
|
|
$this->condition = $condition; |
|
36
|
|
|
} else { |
|
37
|
|
|
$this->condition = call_user_func( [RouteCondition::class, 'make'], func_get_args() ); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritDoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function isSatisfied( RequestInterface $request ) { |
|
45
|
|
|
return ! $this->condition->isSatisfied( $request ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritDoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getArguments( RequestInterface $request ) { |
|
52
|
|
|
return $this->condition->getArguments( $request ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritDoc} |
|
57
|
|
|
* @codeCoverageIgnore |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getUrlWhere() { |
|
60
|
|
|
if ( $this->condition instanceof HasUrlInterface ) { |
|
61
|
|
|
$this->condition->getUrlWhere(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritDoc} |
|
67
|
|
|
* @codeCoverageIgnore |
|
68
|
|
|
*/ |
|
69
|
|
|
public function setUrlWhere( $where ) { |
|
70
|
|
|
if ( $this->condition instanceof HasUrlInterface ) { |
|
71
|
|
|
$this->condition->setUrlWhere( $where ); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|