1 | <?php |
||
5 | trait Condition |
||
6 | { |
||
7 | /** |
||
8 | * @var Application |
||
9 | */ |
||
10 | protected $app; |
||
11 | |||
12 | protected static $conditions = [ |
||
13 | 'class_exists', 'defined', 'function_exists', 'hook', 'is_front_page', 'is_home', |
||
14 | 'is_page_template', 'is_plugin_active', 'is_plugin_inactive', |
||
15 | ]; |
||
16 | |||
17 | /** |
||
18 | * @return bool |
||
19 | */ |
||
20 | public function validate( array $conditions ) |
||
30 | |||
31 | /** |
||
32 | * @param mixed $conditions |
||
33 | * @return array |
||
34 | */ |
||
35 | protected function normalizeCondition( $conditions ) |
||
52 | |||
53 | /** |
||
54 | * @param string $value |
||
55 | * @return bool |
||
56 | */ |
||
57 | protected function validateClassExists( $value ) |
||
61 | |||
62 | /** |
||
63 | * @param string $value |
||
64 | * @return bool |
||
65 | */ |
||
66 | protected function validateDefined( $value ) |
||
70 | |||
71 | /** |
||
72 | * @param string $value |
||
73 | * @return bool |
||
74 | */ |
||
75 | protected function validateFunctionExists( $value ) |
||
79 | |||
80 | /** |
||
81 | * @param string $value |
||
82 | * @return bool |
||
83 | */ |
||
84 | protected function validateHook( $value ) |
||
88 | |||
89 | /** |
||
90 | * @param bool $value |
||
91 | * @return bool |
||
92 | */ |
||
93 | protected function validateIsFrontPage( $value ) |
||
97 | |||
98 | /** |
||
99 | * @param bool $value |
||
100 | * @return bool |
||
101 | */ |
||
102 | protected function validateIsHome( $value ) |
||
106 | |||
107 | /** |
||
108 | * @param string $value |
||
109 | * @return bool |
||
110 | */ |
||
111 | protected function validateIsPageTemplate( $value ) |
||
115 | |||
116 | /** |
||
117 | * @param string $value |
||
118 | * @return bool |
||
119 | */ |
||
120 | protected function validateIsPluginActive( $value ) |
||
124 | |||
125 | /** |
||
126 | * @param string $value |
||
127 | * @return bool |
||
128 | */ |
||
129 | protected function validateIsPluginInactive( $value ) |
||
133 | |||
134 | /** |
||
135 | * @param string $key |
||
136 | * @param mixed $value |
||
137 | * @return bool |
||
138 | */ |
||
139 | protected function validateUnknown( $key, $value ) |
||
143 | |||
144 | /** |
||
145 | * @param bool $toLowerCase |
||
146 | * @return string |
||
147 | */ |
||
148 | abstract protected function getClassname( $toLowerCase = true ); |
||
149 | |||
150 | /** |
||
151 | * @return int |
||
152 | */ |
||
153 | abstract protected function getPostId(); |
||
154 | |||
155 | /** |
||
156 | * @param mixed $value |
||
157 | * @return array |
||
158 | */ |
||
159 | abstract protected function toArray( $value ); |
||
160 | } |
||
161 |