Transformers
1 year ago
BaseLocationCountryRuleProcessor.php
2 years ago
BaseLocationStateRuleProcessor.php
2 years ago
ComparisonOperation.php
2 years ago
ContextPluginsRuleProcessor.php
1 year ago
EvaluateAndGetStatus.php
2 years ago
EvaluateOverrides.php
1 year ago
EvaluationLogger.php
1 year ago
FailRuleProcessor.php
2 years ago
GetRuleProcessor.php
2 years ago
GetRuleProcessorForContext.php
1 year ago
IsEcommerceRuleProcessor.php
2 years ago
IsWooExpressRuleProcessor.php
2 years ago
NotRuleProcessor.php
2 years ago
NoteStatusRuleProcessor.php
2 years ago
OnboardingProfileRuleProcessor.php
2 years ago
OptionRuleProcessor.php
2 years ago
OrRuleProcessor.php
2 years ago
OrderCountRuleProcessor.php
2 years ago
OrdersProvider.php
2 years ago
PassRuleProcessor.php
2 years ago
PluginVersionRuleProcessor.php
2 years ago
PluginsActivatedRuleProcessor.php
2 years ago
ProductCountRuleProcessor.php
1 year ago
PublishAfterTimeRuleProcessor.php
2 years ago
PublishBeforeTimeRuleProcessor.php
2 years ago
RuleEvaluator.php
1 year ago
RuleProcessorInterface.php
2 years ago
StoredStateRuleProcessor.php
2 years ago
StoredStateSetupForProducts.php
2 years ago
TotalPaymentsVolumeProcessor.php
1 year ago
WCAdminActiveForProvider.php
2 years ago
WCAdminActiveForRuleProcessor.php
2 years ago
WooCommerceAdminUpdatedRuleProcessor.php
2 years ago
ContextPluginsRuleProcessor.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 6 | |
| 7 | /** |
| 8 | * Rule processor for context_plugins rules. |
| 9 | * |
| 10 | * Processes the following rule: |
| 11 | * { |
| 12 | * "type": "context_plugins", |
| 13 | * "name": "name of a property in the plugin object", |
| 14 | * "value": "value to match", |
| 15 | * "operation": "operation" |
| 16 | * } |
| 17 | */ |
| 18 | class ContextPluginsRuleProcessor implements RuleProcessorInterface { |
| 19 | |
| 20 | /** |
| 21 | * The list of plugin objects. |
| 22 | * |
| 23 | * Plugin object is unmodified object from https://woocommerce.com/wp-json/wccom/obw-free-extensions/4.0/extensions.json |
| 24 | * |
| 25 | * Example: |
| 26 | * { |
| 27 | * "id": "WooCommerce Shipping", |
| 28 | * "description": "description", |
| 29 | * "is_visible": true, |
| 30 | * "is_built_by_wc": true, |
| 31 | * "key": "woocommerce-shipping", |
| 32 | * } |
| 33 | * |
| 34 | * @var array a list of plugins. |
| 35 | */ |
| 36 | private array $plugins; |
| 37 | |
| 38 | /** |
| 39 | * Constructor. |
| 40 | * |
| 41 | * @param array $plugins a list of plugins. |
| 42 | */ |
| 43 | public function __construct( array $plugins ) { |
| 44 | $this->plugins = $plugins; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Performs a comparison operation against the option value. |
| 49 | * |
| 50 | * @param object $rule The specific rule being processed by this rule processor. |
| 51 | * @param object $stored_state Stored state. |
| 52 | * |
| 53 | * @return bool The result of the operation. |
| 54 | */ |
| 55 | public function process( $rule, $stored_state ) { |
| 56 | foreach ( $this->plugins as $plugin ) { |
| 57 | if ( ! isset( $plugin->{$rule->name} ) ) { |
| 58 | continue; |
| 59 | } |
| 60 | if ( ComparisonOperation::compare( $plugin->{$rule->name}, $rule->value, $rule->operation ) ) { |
| 61 | return true; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Validates the rule. |
| 70 | * |
| 71 | * @param object $rule The rule to validate. |
| 72 | * |
| 73 | * @return bool Pass/fail. |
| 74 | */ |
| 75 | public function validate( $rule ) { |
| 76 | if ( ! isset( $rule->name ) || ! isset( $rule->value ) || ! isset( $rule->operation ) ) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | return true; |
| 81 | } |
| 82 | } |
| 83 |