WooCommerce
1 week ago
AndStrategy.php
1 week ago
ConstantDefinedStrategy.php
1 week ago
ConstantNotDefinedStrategy.php
1 week ago
GetStrategy.php
1 week ago
OrStrategy.php
1 week ago
PostTypeStrategy.php
1 week ago
ShouldShowStrategy.php
1 week ago
GetStrategy.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\ShowDecision; |
| 4 | |
| 5 | /** |
| 6 | * Show when some conditions with $_GET are meet. |
| 7 | */ |
| 8 | class GetStrategy implements ShouldShowStrategy |
| 9 | { |
| 10 | /** |
| 11 | * @var array |
| 12 | */ |
| 13 | private $conditions; |
| 14 | /** |
| 15 | * @param array $conditions Whether to show on the page or not. Array of arrays with condition for _GET. |
| 16 | * |
| 17 | * Inner arrays mean AND, outer arrays mean OR conditions. |
| 18 | * |
| 19 | * ie. [ [ .. and .. and ..] or [ .. and .. and ..] or .. ] |
| 20 | * |
| 21 | */ |
| 22 | public function __construct(array $conditions) |
| 23 | { |
| 24 | $this->conditions = $conditions; |
| 25 | } |
| 26 | /** |
| 27 | * @return bool |
| 28 | */ |
| 29 | public function shouldDisplay() |
| 30 | { |
| 31 | foreach ($this->conditions as $or_conditions) { |
| 32 | $display = \true; |
| 33 | foreach ($or_conditions as $parameter => $value) { |
| 34 | if (!isset($_GET[$parameter]) || $_GET[$parameter] !== $value) { |
| 35 | $display = \false; |
| 36 | } |
| 37 | } |
| 38 | if ($display) { |
| 39 | return $display; |
| 40 | } |
| 41 | } |
| 42 | return \false; |
| 43 | } |
| 44 | } |
| 45 |