| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Contact_Segmentation; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || die(); |
| 6 |
|
| 7 |
/** |
| 8 |
* Class Contact_Segmentation |
| 9 |
* |
| 10 |
* @package Sellkit\Contact_Segmentation |
| 11 |
* @since 1.1.0 |
| 12 |
*/ |
| 13 |
class Operators { |
| 14 |
|
| 15 |
/** |
| 16 |
* Operator names. |
| 17 |
* |
| 18 |
* @var array |
| 19 |
* @since 1.1.0 |
| 20 |
*/ |
| 21 |
public static $names = []; |
| 22 |
|
| 23 |
/** |
| 24 |
* Operator names. |
| 25 |
* |
| 26 |
* @var array |
| 27 |
* @since 1.1.0 |
| 28 |
*/ |
| 29 |
public static $condition_operator_names = []; |
| 30 |
|
| 31 |
/** |
| 32 |
* Operator names. |
| 33 |
* |
| 34 |
* @var array |
| 35 |
* @since 1.1.0 |
| 36 |
*/ |
| 37 |
public static $operators = []; |
| 38 |
|
| 39 |
/** |
| 40 |
* Conditions constructor. |
| 41 |
* |
| 42 |
* @since 1.1.0 |
| 43 |
*/ |
| 44 |
public function __construct() { |
| 45 |
$this->load_operators(); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Loads all of the conditions. |
| 50 |
* |
| 51 |
* @since 1.1.0 |
| 52 |
*/ |
| 53 |
public function load_operators() { |
| 54 |
sellkit()->load_files( [ |
| 55 |
'contact-segmentation/operators/operator-base', |
| 56 |
] ); |
| 57 |
|
| 58 |
$path = trailingslashit( sellkit()->plugin_dir() . 'includes/contact-segmentation/operators' ); |
| 59 |
$file_paths = glob( $path . '*.php' ); |
| 60 |
|
| 61 |
foreach ( $file_paths as $file_path ) { |
| 62 |
if ( ! file_exists( $file_path ) ) { |
| 63 |
continue; |
| 64 |
} |
| 65 |
|
| 66 |
require_once $file_path; |
| 67 |
|
| 68 |
$file_name = str_replace( '.php', '', basename( $file_path ) ); |
| 69 |
$operator_class = str_replace( '-', ' ', $file_name ); |
| 70 |
$operator_class = str_replace( ' ', '_', ucwords( $operator_class ) ); |
| 71 |
$operator_class = "Sellkit\Contact_Segmentation\Operators\\{$operator_class}"; |
| 72 |
|
| 73 |
if ( ! class_exists( $operator_class ) || 'operator-base' === $file_name ) { |
| 74 |
continue; |
| 75 |
} |
| 76 |
|
| 77 |
$operator = new $operator_class(); |
| 78 |
|
| 79 |
$new_conditions = array_fill_keys( $operator->get_conditions(), $operator->get_name() ); |
| 80 |
self::$condition_operator_names = array_merge_recursive( self::$condition_operator_names, $new_conditions ); |
| 81 |
self::$names[ $operator->get_name() ] = $operator->get_title(); |
| 82 |
self::$operators[ $operator->get_name() ] = $operator; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
new Operators(); |
| 88 |
|