class-wc-product-usage-rule-set.php
51 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Product Usage Rule. |
| 4 | * |
| 5 | * This class defines the DTO for passing product feature restriction rules to WooCommerce extensions. |
| 6 | * |
| 7 | * @package WooCommerce\Admin\ProductUsage |
| 8 | */ |
| 9 | |
| 10 | declare( strict_types = 1 ); |
| 11 | |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * WC_Product_Usage_Rule_Set. |
| 19 | */ |
| 20 | class WC_Product_Usage_Rule_Set { |
| 21 | /** |
| 22 | * Set of product feature restriction rules. |
| 23 | * |
| 24 | * @var array|null $rules |
| 25 | */ |
| 26 | protected $rules; |
| 27 | |
| 28 | /** |
| 29 | * Constructor |
| 30 | * |
| 31 | * @param array $rules product feature restriction rules. |
| 32 | */ |
| 33 | public function __construct( $rules ) { |
| 34 | $this->rules = $rules; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Retrieve the value of a rule by name |
| 39 | * |
| 40 | * @param string $rule_name name of the rule to retrieve value. |
| 41 | * @return mixed|null |
| 42 | */ |
| 43 | public function get_rule( string $rule_name ) { |
| 44 | if ( ! isset( $this->rules[ $rule_name ] ) ) { |
| 45 | return null; |
| 46 | } |
| 47 | |
| 48 | return $this->rules[ $rule_name ]; |
| 49 | } |
| 50 | } |
| 51 |