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
PublishBeforeTimeRuleProcessor.php
68 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor for sending before a specified date/time. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | use Automattic\WooCommerce\Admin\DateTimeProvider\CurrentDateTimeProvider; |
| 11 | |
| 12 | /** |
| 13 | * Rule processor for sending before a specified date/time. |
| 14 | */ |
| 15 | class PublishBeforeTimeRuleProcessor implements RuleProcessorInterface { |
| 16 | |
| 17 | /** |
| 18 | * The DateTime provider. |
| 19 | * |
| 20 | * @var DateTimeProviderInterface |
| 21 | */ |
| 22 | protected $date_time_provider; |
| 23 | |
| 24 | /** |
| 25 | * Constructor. |
| 26 | * |
| 27 | * @param DateTimeProviderInterface $date_time_provider The DateTime provider. |
| 28 | */ |
| 29 | public function __construct( $date_time_provider = null ) { |
| 30 | $this->date_time_provider = null === $date_time_provider |
| 31 | ? new CurrentDateTimeProvider() |
| 32 | : $date_time_provider; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Process the rule. |
| 37 | * |
| 38 | * @param object $rule The specific rule being processed by this rule processor. |
| 39 | * @param object $stored_state Stored state. |
| 40 | * |
| 41 | * @return bool Whether the rule passes or not. |
| 42 | */ |
| 43 | public function process( $rule, $stored_state ) { |
| 44 | return $this->date_time_provider->get_now() <= new \DateTime( $rule->publish_before ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Validates the rule. |
| 49 | * |
| 50 | * @param object $rule The rule to validate. |
| 51 | * |
| 52 | * @return bool Pass/fail. |
| 53 | */ |
| 54 | public function validate( $rule ) { |
| 55 | if ( ! isset( $rule->publish_before ) ) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | try { |
| 60 | new \DateTime( $rule->publish_before ); |
| 61 | } catch ( \Throwable $e ) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | } |
| 68 |