woocommerce
/
packages
/
woocommerce-admin
/
src
/
RemoteInboxNotifications
/
StoredStateRuleProcessor.php
ComparisonOperation.php
5 years ago
DataSourcePoller.php
5 years ago
EvaluateAndGetStatus.php
5 years ago
FailRuleProcessor.php
5 years ago
GetRuleProcessor.php
5 years ago
IsEcommerceRuleProcessor.php
5 years ago
NotRuleProcessor.php
5 years ago
OnboardingProfileRuleProcessor.php
5 years ago
OrRuleProcessor.php
5 years ago
OrderCountRuleProcessor.php
5 years ago
OrdersProvider.php
5 years ago
PassRuleProcessor.php
5 years ago
PluginVersionRuleProcessor.php
5 years ago
PluginsActivatedRuleProcessor.php
5 years ago
ProductCountRuleProcessor.php
5 years ago
PublishAfterTimeRuleProcessor.php
5 years ago
PublishBeforeTimeRuleProcessor.php
5 years ago
RemoteInboxNotificationsEngine.php
5 years ago
RuleEvaluator.php
5 years ago
RuleProcessorInterface.php
5 years ago
SpecRunner.php
5 years ago
StoredStateRuleProcessor.php
5 years ago
StoredStateSetupForProducts.php
5 years ago
WCAdminActiveForProvider.php
5 years ago
WCAdminActiveForRuleProcessor.php
5 years ago
StoredStateRuleProcessor.php
59 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor that performs a comparison operation against a value in the |
| 4 | * stored state object. |
| 5 | */ |
| 6 | |
| 7 | namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Rule processor that performs a comparison operation against a value in the |
| 13 | * stored state object. |
| 14 | */ |
| 15 | class StoredStateRuleProcessor implements RuleProcessorInterface { |
| 16 | /** |
| 17 | * Performs a comparison operation against a value in the stored state object. |
| 18 | * |
| 19 | * @param object $rule The rule being processed by this rule processor. |
| 20 | * @param object $stored_state Stored state. |
| 21 | * |
| 22 | * @return bool The result of the operation. |
| 23 | */ |
| 24 | public function process( $rule, $stored_state ) { |
| 25 | if ( ! isset( $stored_state->{$rule->index} ) ) { |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | return ComparisonOperation::compare( |
| 30 | $stored_state->{$rule->index}, |
| 31 | $rule->value, |
| 32 | $rule->operation |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Validates the rule. |
| 38 | * |
| 39 | * @param object $rule The rule to validate. |
| 40 | * |
| 41 | * @return bool Pass/fail. |
| 42 | */ |
| 43 | public function validate( $rule ) { |
| 44 | if ( ! isset( $rule->index ) ) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | if ( ! isset( $rule->value ) ) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | if ( ! isset( $rule->operation ) ) { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | return true; |
| 57 | } |
| 58 | } |
| 59 |