PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.1.9
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.1.9
1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 All 178 releases
disco / app / Attributes / AttributeFactory.php

AttributeFactory.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.1.9, at app/Attributes/AttributeFactory.php

155 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Disco Attribute Factory
4 *
5 * @package Disco
6 * @subpackage Disco\App\Attributes
7 * @category MyCategory
8 */
9
10 namespace Disco\App\Attributes;
11
12 /**
13 * Class AttributeFactory
14 *
15 * @package Disco
16 * @subpackage Disco\App\Attributes
17 * @author Ohidul Islam <wahid0003@gmail.com>
18 * @link https://webappick.com
19 * @license https://opensource.org/licenses/gpl-license.php GNU Public License
20 * @category MyCategory
21 */
22 class AttributeFactory {
23
24 /**
25 * AttributeFactory constructor.
26 */
27 public function __construct() {
28 // class constructor
29 }
30
31 /**
32 * Get Attribute Type, Initialize Class and Return Value.
33 * If Method is Not Found, Return Empty String.
34 *
35 * @param string $method_name Method Name.
36 * @param array $info Class Object.
37 * @return string
38 */
39 public static function get_value( $method_name, $info ) {
40 $class_details = self::get_class_and_method( $method_name, $info );
41
42 if ( ! $class_details ) {
43 return '';
44 }
45
46 list( $class_instance, $method, $key ) = $class_details;
47
48 if ( ! method_exists( $class_instance, $method ) ) {
49 return '';
50 }
51
52 if ( $key ) {
53 return $class_instance->$method( $key );
54 }
55
56 return $class_instance->$method();
57 }
58
59 /**
60 * Get Attribute Type, Initialize Class and Return Value.
61 *
62 * @param string $method_name Method Name.
63 * @param array $info Class Object.
64 * @return array
65 */
66 public static function get_class_and_method( $method_name, $info ) {// phpcs:ignore
67 $prefix_mappings = array(
68 'customer_history' => array(
69 CustomerHistory::class,
70 null,
71 ),
72 'product_history' => array(
73 ProductHistory::class,
74 null,
75 ),
76 'customer' => array(
77 Customer::class,
78 null,
79 ),
80 'cart' => array(
81 Cart::class,
82 null,
83 ),
84 'global_attribute_' => array(
85 Product::class,
86 'get_attribute',
87 ),
88 'custom_attribute_' => array(
89 Product::class,
90 'get_attribute',
91 ),
92 'product_meta_' => array(
93 Product::class,
94 'get_product_meta',
95 ),
96 );
97
98 foreach ( $prefix_mappings as $prefix => $class_and_method ) {
99 if ( strpos( $method_name, $prefix ) !== 0 ) {
100 continue;
101 }
102
103 $class_name = $class_and_method[0];
104
105 if ( $class_and_method[1] ) {
106 $method = $class_and_method[1];
107 } else {
108 $method = $method_name;
109 }
110
111 if ( $method === $method_name ) {
112 $key = null;
113 } else {
114 $key = str_replace( $prefix, '', $method_name );
115 }
116
117 // If the class is Cart or Customer, we don't need to pass any info.
118 if ( $class_name === Cart::class || $class_name === Customer::class ) {
119 return array(
120 new $class_name,
121 $method,
122 $key,
123 );
124 }
125
126 if ( $class_name === Product::class ) {
127 $product = $info['product'];
128 \assert( $product instanceof \WC_Product );
129
130 return array(
131 new $class_name( $product ),
132 $method,
133 $key,
134 );
135 }
136
137 return array(
138 new $class_name( $info ),
139 $method,
140 $key,
141 );
142 }//end foreach
143
144 $product = $info['product'];
145 \assert( $product instanceof \WC_Product );
146
147 return array(
148 new Product( $product ),
149 $method_name,
150 null,
151 );
152 }
153
154 }
155