@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | public static function instance(): EEH_Autoloader |
58 | 58 | { |
59 | 59 | // check if class object is instantiated |
60 | - if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) { |
|
60 | + if ( ! EEH_Autoloader::$_instance instanceof EEH_Autoloader) { |
|
61 | 61 | EEH_Autoloader::$_instance = new EEH_Autoloader(); |
62 | 62 | } |
63 | 63 | return EEH_Autoloader::$_instance; |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public static function espresso_autoloader($class_name) |
74 | 74 | { |
75 | - if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) { |
|
76 | - require_once(EEH_Autoloader::$_autoloaders[ $class_name ]); |
|
75 | + if (isset(EEH_Autoloader::$_autoloaders[$class_name])) { |
|
76 | + require_once(EEH_Autoloader::$_autoloaders[$class_name]); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | } |
130 | - if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) { |
|
131 | - EEH_Autoloader::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path); |
|
130 | + if ( ! isset(EEH_Autoloader::$_autoloaders[$class])) { |
|
131 | + EEH_Autoloader::$_autoloaders[$class] = str_replace(['/', '\\'], '/', $path); |
|
132 | 132 | if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
133 | - EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
133 | + EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | } |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | { |
155 | 155 | EEH_Autoloader::$debug = ''; |
156 | 156 | EEH_Autoloader::register_helpers_autoloaders(); |
157 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
157 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces'); |
|
158 | 158 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
159 | 159 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
160 | 160 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
161 | 161 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
162 | 162 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
164 | 164 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
165 | 165 | Benchmark::displayResults(); |
166 | 166 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public static function register_line_item_display_autoloaders() |
193 | 193 | { |
194 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
194 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public static function register_line_item_filter_autoloaders() |
203 | 203 | { |
204 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
204 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | */ |
212 | 212 | public static function register_template_part_autoloaders() |
213 | 213 | { |
214 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
214 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public static function register_business_classes() |
223 | 223 | { |
224 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
224 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business'); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | Benchmark::startTimer(basename($folder)); |
247 | 247 | } |
248 | 248 | // make sure last char is a / |
249 | - $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : ''; |
|
249 | + $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : ''; |
|
250 | 250 | $class_to_filepath_map = []; |
251 | 251 | $exclude = ['index']; |
252 | 252 | // get all the files in that folder that end in php |
253 | - $filepaths = glob($folder . '*'); |
|
253 | + $filepaths = glob($folder.'*'); |
|
254 | 254 | |
255 | 255 | if (empty($filepaths)) { |
256 | 256 | return; |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | foreach ($filepaths as $filepath) { |
260 | 260 | if (substr($filepath, -4, 4) === '.php') { |
261 | 261 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
262 | - if (! in_array($class_name, $exclude)) { |
|
263 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
262 | + if ( ! in_array($class_name, $exclude)) { |
|
263 | + $class_to_filepath_map [$class_name] = $filepath; |
|
264 | 264 | } |
265 | 265 | } elseif ($recursive) { |
266 | 266 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public static function add_alias(string $class_name, string $alias) |
284 | 284 | { |
285 | - if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) { |
|
286 | - EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ]; |
|
285 | + if (isset(EEH_Autoloader::$_autoloaders[$class_name])) { |
|
286 | + EEH_Autoloader::$_autoloaders[$alias] = EEH_Autoloader::$_autoloaders[$class_name]; |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | } |
@@ -13,275 +13,275 @@ |
||
13 | 13 | */ |
14 | 14 | class EEH_Autoloader extends EEH_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * instance of the EE_System object |
|
18 | - * |
|
19 | - * @var $_instance |
|
20 | - */ |
|
21 | - private static $_instance = null; |
|
22 | - |
|
23 | - /** |
|
24 | - * $_autoloaders |
|
25 | - * @var array $_autoloaders |
|
26 | - */ |
|
27 | - private static $_autoloaders; |
|
28 | - |
|
29 | - /** |
|
30 | - * set to "paths" to display autoloader class => path mappings |
|
31 | - * set to "times" to display autoloader loading times |
|
32 | - * set to "all" to display both |
|
33 | - * |
|
34 | - * @var string $debug |
|
35 | - */ |
|
36 | - public static $debug = false; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - private function __construct() |
|
43 | - { |
|
44 | - if (EEH_Autoloader::$_autoloaders === null) { |
|
45 | - EEH_Autoloader::$_autoloaders = []; |
|
46 | - $this->_register_custom_autoloaders(); |
|
47 | - spl_autoload_register([$this, 'espresso_autoloader']); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return EEH_Autoloader |
|
54 | - */ |
|
55 | - public static function instance(): EEH_Autoloader |
|
56 | - { |
|
57 | - // check if class object is instantiated |
|
58 | - if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) { |
|
59 | - EEH_Autoloader::$_instance = new EEH_Autoloader(); |
|
60 | - } |
|
61 | - return EEH_Autoloader::$_instance; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param $class_name |
|
67 | - * @return void |
|
68 | - * @internal param string $class_name - simple class name ie: session |
|
69 | - * @internal param $className |
|
70 | - */ |
|
71 | - public static function espresso_autoloader($class_name) |
|
72 | - { |
|
73 | - if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) { |
|
74 | - require_once(EEH_Autoloader::$_autoloaders[ $class_name ]); |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
81 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
82 | - * @param bool $debug **deprecated** |
|
83 | - * @throws EE_Error |
|
84 | - */ |
|
85 | - public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
86 | - { |
|
87 | - $class_paths = is_array($class_paths) ? $class_paths : [$class_paths]; |
|
88 | - foreach ($class_paths as $class => $path) { |
|
89 | - // skip all files that are not PHP |
|
90 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
91 | - continue; |
|
92 | - } |
|
93 | - // don't give up! you gotta... |
|
94 | - // get some class |
|
95 | - if (empty($class)) { |
|
96 | - throw new EE_Error( |
|
97 | - sprintf( |
|
98 | - esc_html__( |
|
99 | - 'No Class name was specified while registering an autoloader for the following path: %s.', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - $path |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
106 | - // one day you will find the path young grasshopper |
|
107 | - if (empty($path)) { |
|
108 | - throw new EE_Error( |
|
109 | - sprintf( |
|
110 | - esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), |
|
111 | - $class |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
115 | - // is file readable ? |
|
116 | - if ($read_check && ! is_readable($path)) { |
|
117 | - throw new EE_Error( |
|
118 | - sprintf( |
|
119 | - esc_html__( |
|
120 | - 'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
121 | - 'event_espresso' |
|
122 | - ), |
|
123 | - $class, |
|
124 | - $path |
|
125 | - ) |
|
126 | - ); |
|
127 | - } |
|
128 | - if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) { |
|
129 | - EEH_Autoloader::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path); |
|
130 | - if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
131 | - EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - public static function get_autoloaders(): array |
|
142 | - { |
|
143 | - return EEH_Autoloader::$_autoloaders; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @return void |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - private function _register_custom_autoloaders() |
|
152 | - { |
|
153 | - EEH_Autoloader::$debug = ''; |
|
154 | - EEH_Autoloader::register_helpers_autoloaders(); |
|
155 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
156 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
157 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
158 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
159 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
162 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
163 | - Benchmark::displayResults(); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @throws EE_Error |
|
170 | - */ |
|
171 | - public static function register_helpers_autoloaders() |
|
172 | - { |
|
173 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public static function register_form_sections_autoloaders() |
|
181 | - { |
|
182 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @return void |
|
188 | - * @throws EE_Error |
|
189 | - */ |
|
190 | - public static function register_line_item_display_autoloaders() |
|
191 | - { |
|
192 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @return void |
|
198 | - * @throws EE_Error |
|
199 | - */ |
|
200 | - public static function register_line_item_filter_autoloaders() |
|
201 | - { |
|
202 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @return void |
|
208 | - * @throws EE_Error |
|
209 | - */ |
|
210 | - public static function register_template_part_autoloaders() |
|
211 | - { |
|
212 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @return void |
|
218 | - * @throws EE_Error |
|
219 | - */ |
|
220 | - public static function register_business_classes() |
|
221 | - { |
|
222 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
228 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
229 | - * If that's not the case, you'll need to improve this function or just use |
|
230 | - * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for |
|
231 | - * files, but it only does it once -- not on EACH time the autoloader is used |
|
232 | - * |
|
233 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
234 | - * @param bool $recursive |
|
235 | - * @param bool $debug **deprecated** |
|
236 | - * @throws EE_Error |
|
237 | - */ |
|
238 | - public static function register_autoloaders_for_each_file_in_folder( |
|
239 | - string $folder, |
|
240 | - bool $recursive = false, |
|
241 | - bool $debug = false |
|
242 | - ) { |
|
243 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
244 | - Benchmark::startTimer(basename($folder)); |
|
245 | - } |
|
246 | - // make sure last char is a / |
|
247 | - $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : ''; |
|
248 | - $class_to_filepath_map = []; |
|
249 | - $exclude = ['index']; |
|
250 | - // get all the files in that folder that end in php |
|
251 | - $filepaths = glob($folder . '*'); |
|
252 | - |
|
253 | - if (empty($filepaths)) { |
|
254 | - return; |
|
255 | - } |
|
256 | - |
|
257 | - foreach ($filepaths as $filepath) { |
|
258 | - if (substr($filepath, -4, 4) === '.php') { |
|
259 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
260 | - if (! in_array($class_name, $exclude)) { |
|
261 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
262 | - } |
|
263 | - } elseif ($recursive) { |
|
264 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
265 | - } |
|
266 | - } |
|
267 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
268 | - EEH_Autoloader::register_autoloader($class_to_filepath_map, false, $debug); |
|
269 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
270 | - Benchmark::stopTimer(basename($folder)); |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
277 | - * |
|
278 | - * @param string $class_name - simple class name ie: EE_Session |
|
279 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
280 | - */ |
|
281 | - public static function add_alias(string $class_name, string $alias) |
|
282 | - { |
|
283 | - if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) { |
|
284 | - EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ]; |
|
285 | - } |
|
286 | - } |
|
16 | + /** |
|
17 | + * instance of the EE_System object |
|
18 | + * |
|
19 | + * @var $_instance |
|
20 | + */ |
|
21 | + private static $_instance = null; |
|
22 | + |
|
23 | + /** |
|
24 | + * $_autoloaders |
|
25 | + * @var array $_autoloaders |
|
26 | + */ |
|
27 | + private static $_autoloaders; |
|
28 | + |
|
29 | + /** |
|
30 | + * set to "paths" to display autoloader class => path mappings |
|
31 | + * set to "times" to display autoloader loading times |
|
32 | + * set to "all" to display both |
|
33 | + * |
|
34 | + * @var string $debug |
|
35 | + */ |
|
36 | + public static $debug = false; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + private function __construct() |
|
43 | + { |
|
44 | + if (EEH_Autoloader::$_autoloaders === null) { |
|
45 | + EEH_Autoloader::$_autoloaders = []; |
|
46 | + $this->_register_custom_autoloaders(); |
|
47 | + spl_autoload_register([$this, 'espresso_autoloader']); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return EEH_Autoloader |
|
54 | + */ |
|
55 | + public static function instance(): EEH_Autoloader |
|
56 | + { |
|
57 | + // check if class object is instantiated |
|
58 | + if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) { |
|
59 | + EEH_Autoloader::$_instance = new EEH_Autoloader(); |
|
60 | + } |
|
61 | + return EEH_Autoloader::$_instance; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param $class_name |
|
67 | + * @return void |
|
68 | + * @internal param string $class_name - simple class name ie: session |
|
69 | + * @internal param $className |
|
70 | + */ |
|
71 | + public static function espresso_autoloader($class_name) |
|
72 | + { |
|
73 | + if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) { |
|
74 | + require_once(EEH_Autoloader::$_autoloaders[ $class_name ]); |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
81 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
82 | + * @param bool $debug **deprecated** |
|
83 | + * @throws EE_Error |
|
84 | + */ |
|
85 | + public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
86 | + { |
|
87 | + $class_paths = is_array($class_paths) ? $class_paths : [$class_paths]; |
|
88 | + foreach ($class_paths as $class => $path) { |
|
89 | + // skip all files that are not PHP |
|
90 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
91 | + continue; |
|
92 | + } |
|
93 | + // don't give up! you gotta... |
|
94 | + // get some class |
|
95 | + if (empty($class)) { |
|
96 | + throw new EE_Error( |
|
97 | + sprintf( |
|
98 | + esc_html__( |
|
99 | + 'No Class name was specified while registering an autoloader for the following path: %s.', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + $path |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | + // one day you will find the path young grasshopper |
|
107 | + if (empty($path)) { |
|
108 | + throw new EE_Error( |
|
109 | + sprintf( |
|
110 | + esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), |
|
111 | + $class |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | + // is file readable ? |
|
116 | + if ($read_check && ! is_readable($path)) { |
|
117 | + throw new EE_Error( |
|
118 | + sprintf( |
|
119 | + esc_html__( |
|
120 | + 'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
121 | + 'event_espresso' |
|
122 | + ), |
|
123 | + $class, |
|
124 | + $path |
|
125 | + ) |
|
126 | + ); |
|
127 | + } |
|
128 | + if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) { |
|
129 | + EEH_Autoloader::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path); |
|
130 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
131 | + EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + public static function get_autoloaders(): array |
|
142 | + { |
|
143 | + return EEH_Autoloader::$_autoloaders; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @return void |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + private function _register_custom_autoloaders() |
|
152 | + { |
|
153 | + EEH_Autoloader::$debug = ''; |
|
154 | + EEH_Autoloader::register_helpers_autoloaders(); |
|
155 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
156 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
157 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
158 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
159 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
162 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
163 | + Benchmark::displayResults(); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @throws EE_Error |
|
170 | + */ |
|
171 | + public static function register_helpers_autoloaders() |
|
172 | + { |
|
173 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public static function register_form_sections_autoloaders() |
|
181 | + { |
|
182 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @return void |
|
188 | + * @throws EE_Error |
|
189 | + */ |
|
190 | + public static function register_line_item_display_autoloaders() |
|
191 | + { |
|
192 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + * @throws EE_Error |
|
199 | + */ |
|
200 | + public static function register_line_item_filter_autoloaders() |
|
201 | + { |
|
202 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @return void |
|
208 | + * @throws EE_Error |
|
209 | + */ |
|
210 | + public static function register_template_part_autoloaders() |
|
211 | + { |
|
212 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @return void |
|
218 | + * @throws EE_Error |
|
219 | + */ |
|
220 | + public static function register_business_classes() |
|
221 | + { |
|
222 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
228 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
229 | + * If that's not the case, you'll need to improve this function or just use |
|
230 | + * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for |
|
231 | + * files, but it only does it once -- not on EACH time the autoloader is used |
|
232 | + * |
|
233 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
234 | + * @param bool $recursive |
|
235 | + * @param bool $debug **deprecated** |
|
236 | + * @throws EE_Error |
|
237 | + */ |
|
238 | + public static function register_autoloaders_for_each_file_in_folder( |
|
239 | + string $folder, |
|
240 | + bool $recursive = false, |
|
241 | + bool $debug = false |
|
242 | + ) { |
|
243 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
244 | + Benchmark::startTimer(basename($folder)); |
|
245 | + } |
|
246 | + // make sure last char is a / |
|
247 | + $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : ''; |
|
248 | + $class_to_filepath_map = []; |
|
249 | + $exclude = ['index']; |
|
250 | + // get all the files in that folder that end in php |
|
251 | + $filepaths = glob($folder . '*'); |
|
252 | + |
|
253 | + if (empty($filepaths)) { |
|
254 | + return; |
|
255 | + } |
|
256 | + |
|
257 | + foreach ($filepaths as $filepath) { |
|
258 | + if (substr($filepath, -4, 4) === '.php') { |
|
259 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
260 | + if (! in_array($class_name, $exclude)) { |
|
261 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
262 | + } |
|
263 | + } elseif ($recursive) { |
|
264 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
265 | + } |
|
266 | + } |
|
267 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
268 | + EEH_Autoloader::register_autoloader($class_to_filepath_map, false, $debug); |
|
269 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
270 | + Benchmark::stopTimer(basename($folder)); |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
277 | + * |
|
278 | + * @param string $class_name - simple class name ie: EE_Session |
|
279 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
280 | + */ |
|
281 | + public static function add_alias(string $class_name, string $alias) |
|
282 | + { |
|
283 | + if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) { |
|
284 | + EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ]; |
|
285 | + } |
|
286 | + } |
|
287 | 287 | } |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function prefixes(string $prefix = ''): array |
71 | 71 | { |
72 | - if (! empty($prefix)) { |
|
72 | + if ( ! empty($prefix)) { |
|
73 | 73 | // are there any base directories for this namespace prefix? |
74 | - return isset($this->prefixes[ $prefix ]) ? $this->prefixes[ $prefix ] : []; |
|
74 | + return isset($this->prefixes[$prefix]) ? $this->prefixes[$prefix] : []; |
|
75 | 75 | } |
76 | 76 | return $this->prefixes; |
77 | 77 | } |
@@ -100,20 +100,20 @@ discard block |
||
100 | 100 | public function addNamespace(string $prefix, string $base_dir, bool $prepend = false): bool |
101 | 101 | { |
102 | 102 | // normalize namespace prefix |
103 | - $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
103 | + $prefix = trim($prefix, Psr4Autoloader::NS).Psr4Autoloader::NS; |
|
104 | 104 | // normalize the base directory with a trailing separator |
105 | 105 | $base_dir = EEH_File::standardise_and_end_with_directory_separator($base_dir); |
106 | 106 | // initialize the namespace prefix array |
107 | - if (! isset($this->prefixes[ $prefix ])) { |
|
108 | - $this->prefixes[ $prefix ] = []; |
|
107 | + if ( ! isset($this->prefixes[$prefix])) { |
|
108 | + $this->prefixes[$prefix] = []; |
|
109 | 109 | } |
110 | 110 | // retain the base directory for the namespace prefix |
111 | 111 | if ($prepend) { |
112 | - array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
112 | + array_unshift($this->prefixes[$prefix], $base_dir); |
|
113 | 113 | } else { |
114 | - $this->prefixes[ $prefix ][] = $base_dir; |
|
114 | + $this->prefixes[$prefix][] = $base_dir; |
|
115 | 115 | } |
116 | - return isset($this->prefixes[ $prefix ]); |
|
116 | + return isset($this->prefixes[$prefix]); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 |
@@ -46,147 +46,147 @@ |
||
46 | 46 | */ |
47 | 47 | class Psr4Autoloader |
48 | 48 | { |
49 | - /** |
|
50 | - * namespace separator |
|
51 | - */ |
|
52 | - const NS = '\\'; |
|
53 | - |
|
54 | - /** |
|
55 | - * An associative array where the key is a namespace prefix and the value |
|
56 | - * is an array of base directories for classes in that namespace. |
|
57 | - * |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $prefixes = []; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * returns an array of registered namespace prefixes |
|
65 | - * |
|
66 | - * @param string $prefix |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function prefixes(string $prefix = ''): array |
|
70 | - { |
|
71 | - if (! empty($prefix)) { |
|
72 | - // are there any base directories for this namespace prefix? |
|
73 | - return isset($this->prefixes[ $prefix ]) ? $this->prefixes[ $prefix ] : []; |
|
74 | - } |
|
75 | - return $this->prefixes; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Register loader with SPL autoloader stack. |
|
81 | - * |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function register() |
|
85 | - { |
|
86 | - spl_autoload_register([$this, 'loadClass']); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Adds a base directory for a namespace prefix. |
|
92 | - * |
|
93 | - * @param string $prefix The namespace prefix. |
|
94 | - * @param string $base_dir A base directory for class files in the namespace. |
|
95 | - * @param bool $prepend If true, prepend the base directory to the stack instead of appending it; |
|
96 | - * this causes it to be searched first rather than last. |
|
97 | - * @return bool returns TRUE if the namespace was successfully added |
|
98 | - */ |
|
99 | - public function addNamespace(string $prefix, string $base_dir, bool $prepend = false): bool |
|
100 | - { |
|
101 | - // normalize namespace prefix |
|
102 | - $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
103 | - // normalize the base directory with a trailing separator |
|
104 | - $base_dir = EEH_File::standardise_and_end_with_directory_separator($base_dir); |
|
105 | - // initialize the namespace prefix array |
|
106 | - if (! isset($this->prefixes[ $prefix ])) { |
|
107 | - $this->prefixes[ $prefix ] = []; |
|
108 | - } |
|
109 | - // retain the base directory for the namespace prefix |
|
110 | - if ($prepend) { |
|
111 | - array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
112 | - } else { |
|
113 | - $this->prefixes[ $prefix ][] = $base_dir; |
|
114 | - } |
|
115 | - return isset($this->prefixes[ $prefix ]); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Loads the class file for a given class name. |
|
121 | - * |
|
122 | - * @param string $class The fully-qualified class name. |
|
123 | - * @return string The mapped file name on success, or boolean false on failure. |
|
124 | - */ |
|
125 | - public function loadClass(string $class): string |
|
126 | - { |
|
127 | - // the current namespace prefix |
|
128 | - $prefix = $class; |
|
129 | - // work backwards through the namespace names of the fully-qualified |
|
130 | - // class name to find a mapped file name |
|
131 | - while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) { |
|
132 | - // retain the trailing namespace separator in the prefix |
|
133 | - $prefix = substr($class, 0, $pos + 1); |
|
134 | - // the rest is the relative class name |
|
135 | - $relative_class = substr($class, $pos + 1); |
|
136 | - // try to load a mapped file for the prefix and relative class |
|
137 | - $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
|
138 | - if ($mapped_file) { |
|
139 | - return $mapped_file; |
|
140 | - } |
|
141 | - // remove the trailing namespace separator for the next iteration of strrpos() |
|
142 | - $prefix = rtrim($prefix, Psr4Autoloader::NS); |
|
143 | - } |
|
144 | - // never found a mapped file |
|
145 | - return ''; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Load the mapped file for a namespace prefix and relative class. |
|
151 | - * |
|
152 | - * @param string $prefix The namespace prefix. |
|
153 | - * @param string $relative_class The relative class name. |
|
154 | - * @return mixed Boolean false if no mapped file can be loaded, |
|
155 | - * or the name of the mapped file that was loaded. |
|
156 | - */ |
|
157 | - protected function loadMappedFile(string $prefix, string $relative_class) |
|
158 | - { |
|
159 | - // look through base directories for this namespace prefix |
|
160 | - foreach ($this->prefixes($prefix) as $base_dir) { |
|
161 | - // replace the namespace prefix with the base directory, |
|
162 | - // replace namespace separators with directory separators |
|
163 | - // in the relative class name, append with .php |
|
164 | - $file = $base_dir |
|
165 | - . str_replace(Psr4Autoloader::NS, '/', $relative_class) |
|
166 | - . '.php'; |
|
167 | - // if the mapped file exists, require it |
|
168 | - if ($this->requireFile($file)) { |
|
169 | - // yes, we're done |
|
170 | - return $file; |
|
171 | - } |
|
172 | - } |
|
173 | - // never found it |
|
174 | - return false; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * If a file exists, require it from the file system. |
|
180 | - * |
|
181 | - * @param string $file The file to require. |
|
182 | - * @return bool True if the file exists, false if not. |
|
183 | - */ |
|
184 | - protected function requireFile(string $file): bool |
|
185 | - { |
|
186 | - if (file_exists($file)) { |
|
187 | - require $file; |
|
188 | - return true; |
|
189 | - } |
|
190 | - return false; |
|
191 | - } |
|
49 | + /** |
|
50 | + * namespace separator |
|
51 | + */ |
|
52 | + const NS = '\\'; |
|
53 | + |
|
54 | + /** |
|
55 | + * An associative array where the key is a namespace prefix and the value |
|
56 | + * is an array of base directories for classes in that namespace. |
|
57 | + * |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $prefixes = []; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * returns an array of registered namespace prefixes |
|
65 | + * |
|
66 | + * @param string $prefix |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function prefixes(string $prefix = ''): array |
|
70 | + { |
|
71 | + if (! empty($prefix)) { |
|
72 | + // are there any base directories for this namespace prefix? |
|
73 | + return isset($this->prefixes[ $prefix ]) ? $this->prefixes[ $prefix ] : []; |
|
74 | + } |
|
75 | + return $this->prefixes; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Register loader with SPL autoloader stack. |
|
81 | + * |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function register() |
|
85 | + { |
|
86 | + spl_autoload_register([$this, 'loadClass']); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Adds a base directory for a namespace prefix. |
|
92 | + * |
|
93 | + * @param string $prefix The namespace prefix. |
|
94 | + * @param string $base_dir A base directory for class files in the namespace. |
|
95 | + * @param bool $prepend If true, prepend the base directory to the stack instead of appending it; |
|
96 | + * this causes it to be searched first rather than last. |
|
97 | + * @return bool returns TRUE if the namespace was successfully added |
|
98 | + */ |
|
99 | + public function addNamespace(string $prefix, string $base_dir, bool $prepend = false): bool |
|
100 | + { |
|
101 | + // normalize namespace prefix |
|
102 | + $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
103 | + // normalize the base directory with a trailing separator |
|
104 | + $base_dir = EEH_File::standardise_and_end_with_directory_separator($base_dir); |
|
105 | + // initialize the namespace prefix array |
|
106 | + if (! isset($this->prefixes[ $prefix ])) { |
|
107 | + $this->prefixes[ $prefix ] = []; |
|
108 | + } |
|
109 | + // retain the base directory for the namespace prefix |
|
110 | + if ($prepend) { |
|
111 | + array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
112 | + } else { |
|
113 | + $this->prefixes[ $prefix ][] = $base_dir; |
|
114 | + } |
|
115 | + return isset($this->prefixes[ $prefix ]); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Loads the class file for a given class name. |
|
121 | + * |
|
122 | + * @param string $class The fully-qualified class name. |
|
123 | + * @return string The mapped file name on success, or boolean false on failure. |
|
124 | + */ |
|
125 | + public function loadClass(string $class): string |
|
126 | + { |
|
127 | + // the current namespace prefix |
|
128 | + $prefix = $class; |
|
129 | + // work backwards through the namespace names of the fully-qualified |
|
130 | + // class name to find a mapped file name |
|
131 | + while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) { |
|
132 | + // retain the trailing namespace separator in the prefix |
|
133 | + $prefix = substr($class, 0, $pos + 1); |
|
134 | + // the rest is the relative class name |
|
135 | + $relative_class = substr($class, $pos + 1); |
|
136 | + // try to load a mapped file for the prefix and relative class |
|
137 | + $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
|
138 | + if ($mapped_file) { |
|
139 | + return $mapped_file; |
|
140 | + } |
|
141 | + // remove the trailing namespace separator for the next iteration of strrpos() |
|
142 | + $prefix = rtrim($prefix, Psr4Autoloader::NS); |
|
143 | + } |
|
144 | + // never found a mapped file |
|
145 | + return ''; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Load the mapped file for a namespace prefix and relative class. |
|
151 | + * |
|
152 | + * @param string $prefix The namespace prefix. |
|
153 | + * @param string $relative_class The relative class name. |
|
154 | + * @return mixed Boolean false if no mapped file can be loaded, |
|
155 | + * or the name of the mapped file that was loaded. |
|
156 | + */ |
|
157 | + protected function loadMappedFile(string $prefix, string $relative_class) |
|
158 | + { |
|
159 | + // look through base directories for this namespace prefix |
|
160 | + foreach ($this->prefixes($prefix) as $base_dir) { |
|
161 | + // replace the namespace prefix with the base directory, |
|
162 | + // replace namespace separators with directory separators |
|
163 | + // in the relative class name, append with .php |
|
164 | + $file = $base_dir |
|
165 | + . str_replace(Psr4Autoloader::NS, '/', $relative_class) |
|
166 | + . '.php'; |
|
167 | + // if the mapped file exists, require it |
|
168 | + if ($this->requireFile($file)) { |
|
169 | + // yes, we're done |
|
170 | + return $file; |
|
171 | + } |
|
172 | + } |
|
173 | + // never found it |
|
174 | + return false; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * If a file exists, require it from the file system. |
|
180 | + * |
|
181 | + * @param string $file The file to require. |
|
182 | + * @return bool True if the file exists, false if not. |
|
183 | + */ |
|
184 | + protected function requireFile(string $file): bool |
|
185 | + { |
|
186 | + if (file_exists($file)) { |
|
187 | + require $file; |
|
188 | + return true; |
|
189 | + } |
|
190 | + return false; |
|
191 | + } |
|
192 | 192 | } |
@@ -23,109 +23,109 @@ |
||
23 | 23 | */ |
24 | 24 | class AddonManager |
25 | 25 | { |
26 | - /** |
|
27 | - * @var AddonCollection |
|
28 | - */ |
|
29 | - private $addons; |
|
26 | + /** |
|
27 | + * @var AddonCollection |
|
28 | + */ |
|
29 | + private $addons; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var IncompatibleAddonHandler |
|
33 | - */ |
|
34 | - private $incompatible_addon_handler; |
|
31 | + /** |
|
32 | + * @var IncompatibleAddonHandler |
|
33 | + */ |
|
34 | + private $incompatible_addon_handler; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var Psr4Autoloader |
|
38 | - */ |
|
39 | - private $psr4_loader; |
|
36 | + /** |
|
37 | + * @var Psr4Autoloader |
|
38 | + */ |
|
39 | + private $psr4_loader; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var RegisterV1Addon |
|
43 | - */ |
|
44 | - private $register_v1_addon; |
|
41 | + /** |
|
42 | + * @var RegisterV1Addon |
|
43 | + */ |
|
44 | + private $register_v1_addon; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var ThirdPartyPluginHandler |
|
48 | - */ |
|
49 | - private $third_party_plugin_handler; |
|
46 | + /** |
|
47 | + * @var ThirdPartyPluginHandler |
|
48 | + */ |
|
49 | + private $third_party_plugin_handler; |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * AddonManager constructor. |
|
54 | - * |
|
55 | - * @param AddonCollection $addons |
|
56 | - * @param Psr4Autoloader $psr4_loader |
|
57 | - * @param RegisterV1Addon $register_v1_addon |
|
58 | - * @param IncompatibleAddonHandler $incompatible_addon_handler |
|
59 | - * @param ThirdPartyPluginHandler $third_party_plugin_handler |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - AddonCollection $addons, |
|
63 | - Psr4Autoloader $psr4_loader, |
|
64 | - RegisterV1Addon $register_v1_addon, |
|
65 | - IncompatibleAddonHandler $incompatible_addon_handler, |
|
66 | - ThirdPartyPluginHandler $third_party_plugin_handler |
|
67 | - ) { |
|
68 | - $this->addons = $addons; |
|
69 | - $this->psr4_loader = $psr4_loader; |
|
70 | - $this->register_v1_addon = $register_v1_addon; |
|
71 | - $this->incompatible_addon_handler = $incompatible_addon_handler; |
|
72 | - $this->third_party_plugin_handler = $third_party_plugin_handler; |
|
73 | - } |
|
52 | + /** |
|
53 | + * AddonManager constructor. |
|
54 | + * |
|
55 | + * @param AddonCollection $addons |
|
56 | + * @param Psr4Autoloader $psr4_loader |
|
57 | + * @param RegisterV1Addon $register_v1_addon |
|
58 | + * @param IncompatibleAddonHandler $incompatible_addon_handler |
|
59 | + * @param ThirdPartyPluginHandler $third_party_plugin_handler |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + AddonCollection $addons, |
|
63 | + Psr4Autoloader $psr4_loader, |
|
64 | + RegisterV1Addon $register_v1_addon, |
|
65 | + IncompatibleAddonHandler $incompatible_addon_handler, |
|
66 | + ThirdPartyPluginHandler $third_party_plugin_handler |
|
67 | + ) { |
|
68 | + $this->addons = $addons; |
|
69 | + $this->psr4_loader = $psr4_loader; |
|
70 | + $this->register_v1_addon = $register_v1_addon; |
|
71 | + $this->incompatible_addon_handler = $incompatible_addon_handler; |
|
72 | + $this->third_party_plugin_handler = $third_party_plugin_handler; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * @throws Exception |
|
78 | - */ |
|
79 | - public function initialize() |
|
80 | - { |
|
81 | - // set autoloaders for all of the classes implementing the legacy EEI_Plugin_API |
|
82 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
83 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
84 | - } |
|
76 | + /** |
|
77 | + * @throws Exception |
|
78 | + */ |
|
79 | + public function initialize() |
|
80 | + { |
|
81 | + // set autoloaders for all of the classes implementing the legacy EEI_Plugin_API |
|
82 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
83 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @throws Exception |
|
89 | - */ |
|
90 | - public function loadAddons() |
|
91 | - { |
|
92 | - try { |
|
93 | - $this->incompatible_addon_handler->deactivateIncompatibleAddons(); |
|
94 | - // legacy add-on API |
|
95 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
96 | - // new add-on API that uses versioning |
|
97 | - do_action( |
|
98 | - 'AHEE__EventEspresso_core_services_addon_AddonManager__initialize__addons', |
|
99 | - $this->addons, |
|
100 | - espresso_version() |
|
101 | - ); |
|
102 | - // addons are responsible for loading their AddonApiVersion into the AddonCollection |
|
103 | - foreach ($this->addons as $addon) { |
|
104 | - if ($addon instanceof AddonApiVersion) { |
|
105 | - $this->registerAddon($addon); |
|
106 | - } |
|
107 | - } |
|
108 | - $this->third_party_plugin_handler->loadPlugins(); |
|
109 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
110 | - } catch (Exception $exception) { |
|
111 | - new ExceptionStackTraceDisplay($exception); |
|
112 | - } |
|
113 | - } |
|
87 | + /** |
|
88 | + * @throws Exception |
|
89 | + */ |
|
90 | + public function loadAddons() |
|
91 | + { |
|
92 | + try { |
|
93 | + $this->incompatible_addon_handler->deactivateIncompatibleAddons(); |
|
94 | + // legacy add-on API |
|
95 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
96 | + // new add-on API that uses versioning |
|
97 | + do_action( |
|
98 | + 'AHEE__EventEspresso_core_services_addon_AddonManager__initialize__addons', |
|
99 | + $this->addons, |
|
100 | + espresso_version() |
|
101 | + ); |
|
102 | + // addons are responsible for loading their AddonApiVersion into the AddonCollection |
|
103 | + foreach ($this->addons as $addon) { |
|
104 | + if ($addon instanceof AddonApiVersion) { |
|
105 | + $this->registerAddon($addon); |
|
106 | + } |
|
107 | + } |
|
108 | + $this->third_party_plugin_handler->loadPlugins(); |
|
109 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
110 | + } catch (Exception $exception) { |
|
111 | + new ExceptionStackTraceDisplay($exception); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * @param AddonApiVersion $addon |
|
118 | - * @throws EE_Error |
|
119 | - */ |
|
120 | - private function registerAddon(AddonApiVersion $addon) |
|
121 | - { |
|
122 | - // first register addon namespace so that FQCNs resolve correctly |
|
123 | - $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/'); |
|
124 | - // then allow add-on to perform any other setup that relied on PSR4 autoloading |
|
125 | - $addon->initialize(); |
|
126 | - // now register each addon based on it's API version |
|
127 | - if ($addon instanceof AddonApiV1) { |
|
128 | - $this->register_v1_addon->register($addon); |
|
129 | - } |
|
130 | - } |
|
116 | + /** |
|
117 | + * @param AddonApiVersion $addon |
|
118 | + * @throws EE_Error |
|
119 | + */ |
|
120 | + private function registerAddon(AddonApiVersion $addon) |
|
121 | + { |
|
122 | + // first register addon namespace so that FQCNs resolve correctly |
|
123 | + $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/'); |
|
124 | + // then allow add-on to perform any other setup that relied on PSR4 autoloading |
|
125 | + $addon->initialize(); |
|
126 | + // now register each addon based on it's API version |
|
127 | + if ($addon instanceof AddonApiV1) { |
|
128 | + $this->register_v1_addon->register($addon); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | { |
81 | 81 | // set autoloaders for all of the classes implementing the legacy EEI_Plugin_API |
82 | 82 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
83 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
83 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | private function registerAddon(AddonApiVersion $addon) |
121 | 121 | { |
122 | 122 | // first register addon namespace so that FQCNs resolve correctly |
123 | - $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/'); |
|
123 | + $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()).'/src/'); |
|
124 | 124 | // then allow add-on to perform any other setup that relied on PSR4 autoloading |
125 | 125 | $addon->initialize(); |
126 | 126 | // now register each addon based on it's API version |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | string $load_callback, |
44 | 44 | string $plugin_file_constant |
45 | 45 | ) { |
46 | - if (! defined($version_constant)) { |
|
46 | + if ( ! defined($version_constant)) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | $addon_version = constant($version_constant); |
50 | 50 | if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
51 | 51 | remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
52 | - if (! function_exists('deactivate_plugins')) { |
|
53 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
52 | + if ( ! function_exists('deactivate_plugins')) { |
|
53 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
54 | 54 | } |
55 | 55 | deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
56 | 56 | unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $min_version_required |
65 | 65 | ), |
66 | 66 | __FILE__, |
67 | - __FUNCTION__ . "({$addon_name})", |
|
67 | + __FUNCTION__."({$addon_name})", |
|
68 | 68 | __LINE__ |
69 | 69 | ); |
70 | 70 | EE_Error::get_notices(false, true); |
@@ -6,75 +6,75 @@ |
||
6 | 6 | |
7 | 7 | class IncompatibleAddonHandler |
8 | 8 | { |
9 | - /** |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function deactivateIncompatibleAddons() |
|
13 | - { |
|
14 | - $this->deactivateIncompatibleAddon( |
|
15 | - 'Wait Lists', |
|
16 | - 'EE_WAIT_LISTS_VERSION', |
|
17 | - '1.0.0.beta.074', |
|
18 | - 'load_espresso_wait_lists', |
|
19 | - 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
20 | - ); |
|
21 | - $this->deactivateIncompatibleAddon( |
|
22 | - 'Automated Upcoming Event Notifications', |
|
23 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
24 | - '1.0.0.beta.091', |
|
25 | - 'load_espresso_automated_upcoming_event_notification', |
|
26 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
27 | - ); |
|
28 | - // $this->deactivateIncompatibleAddon( |
|
29 | - // 'WP Users Integration', |
|
30 | - // 'EE_WPUSERS_VERSION', |
|
31 | - // '2.1.0.rc.003', |
|
32 | - // 'load_ee_core_wpusers', |
|
33 | - // 'EE_WPUSERS_PLUGIN_FILE' |
|
34 | - // ); |
|
35 | - } |
|
9 | + /** |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function deactivateIncompatibleAddons() |
|
13 | + { |
|
14 | + $this->deactivateIncompatibleAddon( |
|
15 | + 'Wait Lists', |
|
16 | + 'EE_WAIT_LISTS_VERSION', |
|
17 | + '1.0.0.beta.074', |
|
18 | + 'load_espresso_wait_lists', |
|
19 | + 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
20 | + ); |
|
21 | + $this->deactivateIncompatibleAddon( |
|
22 | + 'Automated Upcoming Event Notifications', |
|
23 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
24 | + '1.0.0.beta.091', |
|
25 | + 'load_espresso_automated_upcoming_event_notification', |
|
26 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
27 | + ); |
|
28 | + // $this->deactivateIncompatibleAddon( |
|
29 | + // 'WP Users Integration', |
|
30 | + // 'EE_WPUSERS_VERSION', |
|
31 | + // '2.1.0.rc.003', |
|
32 | + // 'load_ee_core_wpusers', |
|
33 | + // 'EE_WPUSERS_PLUGIN_FILE' |
|
34 | + // ); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @param string $addon_name |
|
40 | - * @param string $version_constant |
|
41 | - * @param string $min_version_required |
|
42 | - * @param string $load_callback |
|
43 | - * @param string $plugin_file_constant |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - private function deactivateIncompatibleAddon( |
|
47 | - string $addon_name, |
|
48 | - string $version_constant, |
|
49 | - string $min_version_required, |
|
50 | - string $load_callback, |
|
51 | - string $plugin_file_constant |
|
52 | - ) { |
|
53 | - if (! defined($version_constant)) { |
|
54 | - return; |
|
55 | - } |
|
56 | - $addon_version = constant($version_constant); |
|
57 | - if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
58 | - remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
59 | - if (! function_exists('deactivate_plugins')) { |
|
60 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
61 | - } |
|
62 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
63 | - unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
64 | - EE_Error::add_error( |
|
65 | - sprintf( |
|
66 | - esc_html__( |
|
67 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
68 | - 'event_espresso' |
|
69 | - ), |
|
70 | - $addon_name, |
|
71 | - $min_version_required |
|
72 | - ), |
|
73 | - __FILE__, |
|
74 | - __FUNCTION__ . "({$addon_name})", |
|
75 | - __LINE__ |
|
76 | - ); |
|
77 | - EE_Error::get_notices(false, true); |
|
78 | - } |
|
79 | - } |
|
38 | + /** |
|
39 | + * @param string $addon_name |
|
40 | + * @param string $version_constant |
|
41 | + * @param string $min_version_required |
|
42 | + * @param string $load_callback |
|
43 | + * @param string $plugin_file_constant |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + private function deactivateIncompatibleAddon( |
|
47 | + string $addon_name, |
|
48 | + string $version_constant, |
|
49 | + string $min_version_required, |
|
50 | + string $load_callback, |
|
51 | + string $plugin_file_constant |
|
52 | + ) { |
|
53 | + if (! defined($version_constant)) { |
|
54 | + return; |
|
55 | + } |
|
56 | + $addon_version = constant($version_constant); |
|
57 | + if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
58 | + remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
59 | + if (! function_exists('deactivate_plugins')) { |
|
60 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
61 | + } |
|
62 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
63 | + unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
64 | + EE_Error::add_error( |
|
65 | + sprintf( |
|
66 | + esc_html__( |
|
67 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
68 | + 'event_espresso' |
|
69 | + ), |
|
70 | + $addon_name, |
|
71 | + $min_version_required |
|
72 | + ), |
|
73 | + __FILE__, |
|
74 | + __FUNCTION__ . "({$addon_name})", |
|
75 | + __LINE__ |
|
76 | + ); |
|
77 | + EE_Error::get_notices(false, true); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | } |
@@ -19,286 +19,286 @@ |
||
19 | 19 | */ |
20 | 20 | abstract class AddonApiVersion |
21 | 21 | { |
22 | - const V1 = 1; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var int one of the API_VERSION_* constants from above |
|
26 | - */ |
|
27 | - private $api_version; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var DomainInterface |
|
31 | - */ |
|
32 | - private $domain; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var Version minimum version of EE core that the add-on will work with |
|
36 | - */ |
|
37 | - private $min_core_version; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var Version minimum version of WP core that the add-on will work with |
|
41 | - */ |
|
42 | - private $min_wp_version; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string PascalCase identifier for the add-on. |
|
46 | - * IMPORTANT! there must be a class of the same name in the root of the add-ons /src/domain/ folder |
|
47 | - */ |
|
48 | - private $name; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - private $addon_namespace; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var FilePath |
|
57 | - */ |
|
58 | - private $main_file; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - private $slug; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var Version the current add-on version |
|
67 | - */ |
|
68 | - private $version; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Bootstrap constructor. |
|
73 | - * |
|
74 | - * @param string $slug |
|
75 | - * @param string $name |
|
76 | - * @param string $namespace |
|
77 | - * @param string $version |
|
78 | - * @param string $min_core_version |
|
79 | - * @param string $main_file |
|
80 | - * @param int $api_version |
|
81 | - */ |
|
82 | - protected function __construct( |
|
83 | - string $slug, |
|
84 | - string $name, |
|
85 | - string $namespace, |
|
86 | - string $version, |
|
87 | - string $min_core_version, |
|
88 | - string $main_file, |
|
89 | - int $api_version |
|
90 | - ) { |
|
91 | - $this->setSlug($slug); |
|
92 | - $this->setName($name); |
|
93 | - $this->setNamespace($namespace); |
|
94 | - $this->setMinCoreVersion($min_core_version); |
|
95 | - $this->setMainFile($main_file); |
|
96 | - $this->setVersion($version); |
|
97 | - $this->setApiVersion($api_version); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - public function initialize(): void |
|
105 | - { |
|
106 | - $this->domain = DomainFactory::create( |
|
107 | - "{$this->addon_namespace}\\domain\\Domain", |
|
108 | - $this->main_file, |
|
109 | - $this->version |
|
110 | - ); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return int[] |
|
116 | - */ |
|
117 | - private function validApiVersions(): array |
|
118 | - { |
|
119 | - return [ |
|
120 | - AddonApiVersion::V1, |
|
121 | - ]; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param int $api_version |
|
127 | - */ |
|
128 | - private function setApiVersion(int $api_version): void |
|
129 | - { |
|
130 | - if (! in_array($api_version, $this->validApiVersions())) { |
|
131 | - throw new DomainException( |
|
132 | - esc_html__( |
|
133 | - 'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants', |
|
134 | - 'event_espresso' |
|
135 | - ) |
|
136 | - ); |
|
137 | - } |
|
138 | - $this->api_version = $api_version; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param string $main_file |
|
144 | - */ |
|
145 | - public function setMainFile(string $main_file): void |
|
146 | - { |
|
147 | - $this->main_file = new FilePath($main_file); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $min_core_version |
|
153 | - */ |
|
154 | - private function setMinCoreVersion(string $min_core_version): void |
|
155 | - { |
|
156 | - $this->min_core_version = Version::fromString($min_core_version); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $name |
|
162 | - */ |
|
163 | - public function setName(string $name): void |
|
164 | - { |
|
165 | - $this->name = $name; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param string $namespace |
|
171 | - */ |
|
172 | - private function setNamespace(string $namespace): void |
|
173 | - { |
|
174 | - $this->addon_namespace = $namespace; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param string $slug |
|
180 | - */ |
|
181 | - private function setSlug(string $slug): void |
|
182 | - { |
|
183 | - $valid_slug = sanitize_key($slug); |
|
184 | - if ($slug !== $valid_slug) { |
|
185 | - throw new DomainException( |
|
186 | - esc_html__( |
|
187 | - 'Invalid Add-on "slug"! Please ensure that slug only uses lowercase characters and dashes.', |
|
188 | - 'event_espresso' |
|
189 | - ) |
|
190 | - ); |
|
191 | - } |
|
192 | - $this->slug = $valid_slug; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @param string $version |
|
198 | - */ |
|
199 | - public function setVersion(string $version): void |
|
200 | - { |
|
201 | - $this->version = Version::fromString($version); |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @return int |
|
207 | - */ |
|
208 | - public function apiVersion(): int |
|
209 | - { |
|
210 | - return $this->api_version; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @return DomainInterface |
|
216 | - */ |
|
217 | - public function domain(): DomainInterface |
|
218 | - { |
|
219 | - return $this->domain; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * @return Version|null |
|
225 | - */ |
|
226 | - public function minCoreVersion(): ?Version |
|
227 | - { |
|
228 | - return $this->min_core_version; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @return Version|null |
|
234 | - */ |
|
235 | - public function minWpVersion(): ?Version |
|
236 | - { |
|
237 | - return $this->min_wp_version; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param string $min_wp_version |
|
243 | - */ |
|
244 | - public function setMinWpVersion(string $min_wp_version = EE_MIN_WP_VER_REQUIRED): void |
|
245 | - { |
|
246 | - $this->min_wp_version = Version::fromString($min_wp_version); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function name(): string |
|
254 | - { |
|
255 | - return $this->name; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * FQCN for the domain's EE_Addon class |
|
261 | - * |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function fqcn(): string |
|
265 | - { |
|
266 | - return "{$this->addon_namespace}\\domain\\{$this->name}"; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - public function getNamespace(): string |
|
274 | - { |
|
275 | - return $this->addon_namespace; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @return FilePath |
|
281 | - */ |
|
282 | - public function mainFile(): FilePath |
|
283 | - { |
|
284 | - return $this->main_file; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function slug(): string |
|
292 | - { |
|
293 | - return $this->slug; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * @return Version |
|
299 | - */ |
|
300 | - public function version(): Version |
|
301 | - { |
|
302 | - return $this->version; |
|
303 | - } |
|
22 | + const V1 = 1; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var int one of the API_VERSION_* constants from above |
|
26 | + */ |
|
27 | + private $api_version; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var DomainInterface |
|
31 | + */ |
|
32 | + private $domain; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var Version minimum version of EE core that the add-on will work with |
|
36 | + */ |
|
37 | + private $min_core_version; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var Version minimum version of WP core that the add-on will work with |
|
41 | + */ |
|
42 | + private $min_wp_version; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string PascalCase identifier for the add-on. |
|
46 | + * IMPORTANT! there must be a class of the same name in the root of the add-ons /src/domain/ folder |
|
47 | + */ |
|
48 | + private $name; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + private $addon_namespace; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var FilePath |
|
57 | + */ |
|
58 | + private $main_file; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + private $slug; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var Version the current add-on version |
|
67 | + */ |
|
68 | + private $version; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Bootstrap constructor. |
|
73 | + * |
|
74 | + * @param string $slug |
|
75 | + * @param string $name |
|
76 | + * @param string $namespace |
|
77 | + * @param string $version |
|
78 | + * @param string $min_core_version |
|
79 | + * @param string $main_file |
|
80 | + * @param int $api_version |
|
81 | + */ |
|
82 | + protected function __construct( |
|
83 | + string $slug, |
|
84 | + string $name, |
|
85 | + string $namespace, |
|
86 | + string $version, |
|
87 | + string $min_core_version, |
|
88 | + string $main_file, |
|
89 | + int $api_version |
|
90 | + ) { |
|
91 | + $this->setSlug($slug); |
|
92 | + $this->setName($name); |
|
93 | + $this->setNamespace($namespace); |
|
94 | + $this->setMinCoreVersion($min_core_version); |
|
95 | + $this->setMainFile($main_file); |
|
96 | + $this->setVersion($version); |
|
97 | + $this->setApiVersion($api_version); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + public function initialize(): void |
|
105 | + { |
|
106 | + $this->domain = DomainFactory::create( |
|
107 | + "{$this->addon_namespace}\\domain\\Domain", |
|
108 | + $this->main_file, |
|
109 | + $this->version |
|
110 | + ); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return int[] |
|
116 | + */ |
|
117 | + private function validApiVersions(): array |
|
118 | + { |
|
119 | + return [ |
|
120 | + AddonApiVersion::V1, |
|
121 | + ]; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param int $api_version |
|
127 | + */ |
|
128 | + private function setApiVersion(int $api_version): void |
|
129 | + { |
|
130 | + if (! in_array($api_version, $this->validApiVersions())) { |
|
131 | + throw new DomainException( |
|
132 | + esc_html__( |
|
133 | + 'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants', |
|
134 | + 'event_espresso' |
|
135 | + ) |
|
136 | + ); |
|
137 | + } |
|
138 | + $this->api_version = $api_version; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param string $main_file |
|
144 | + */ |
|
145 | + public function setMainFile(string $main_file): void |
|
146 | + { |
|
147 | + $this->main_file = new FilePath($main_file); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $min_core_version |
|
153 | + */ |
|
154 | + private function setMinCoreVersion(string $min_core_version): void |
|
155 | + { |
|
156 | + $this->min_core_version = Version::fromString($min_core_version); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $name |
|
162 | + */ |
|
163 | + public function setName(string $name): void |
|
164 | + { |
|
165 | + $this->name = $name; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param string $namespace |
|
171 | + */ |
|
172 | + private function setNamespace(string $namespace): void |
|
173 | + { |
|
174 | + $this->addon_namespace = $namespace; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param string $slug |
|
180 | + */ |
|
181 | + private function setSlug(string $slug): void |
|
182 | + { |
|
183 | + $valid_slug = sanitize_key($slug); |
|
184 | + if ($slug !== $valid_slug) { |
|
185 | + throw new DomainException( |
|
186 | + esc_html__( |
|
187 | + 'Invalid Add-on "slug"! Please ensure that slug only uses lowercase characters and dashes.', |
|
188 | + 'event_espresso' |
|
189 | + ) |
|
190 | + ); |
|
191 | + } |
|
192 | + $this->slug = $valid_slug; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param string $version |
|
198 | + */ |
|
199 | + public function setVersion(string $version): void |
|
200 | + { |
|
201 | + $this->version = Version::fromString($version); |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @return int |
|
207 | + */ |
|
208 | + public function apiVersion(): int |
|
209 | + { |
|
210 | + return $this->api_version; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @return DomainInterface |
|
216 | + */ |
|
217 | + public function domain(): DomainInterface |
|
218 | + { |
|
219 | + return $this->domain; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * @return Version|null |
|
225 | + */ |
|
226 | + public function minCoreVersion(): ?Version |
|
227 | + { |
|
228 | + return $this->min_core_version; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @return Version|null |
|
234 | + */ |
|
235 | + public function minWpVersion(): ?Version |
|
236 | + { |
|
237 | + return $this->min_wp_version; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param string $min_wp_version |
|
243 | + */ |
|
244 | + public function setMinWpVersion(string $min_wp_version = EE_MIN_WP_VER_REQUIRED): void |
|
245 | + { |
|
246 | + $this->min_wp_version = Version::fromString($min_wp_version); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function name(): string |
|
254 | + { |
|
255 | + return $this->name; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * FQCN for the domain's EE_Addon class |
|
261 | + * |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function fqcn(): string |
|
265 | + { |
|
266 | + return "{$this->addon_namespace}\\domain\\{$this->name}"; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + public function getNamespace(): string |
|
274 | + { |
|
275 | + return $this->addon_namespace; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @return FilePath |
|
281 | + */ |
|
282 | + public function mainFile(): FilePath |
|
283 | + { |
|
284 | + return $this->main_file; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function slug(): string |
|
292 | + { |
|
293 | + return $this->slug; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * @return Version |
|
299 | + */ |
|
300 | + public function version(): Version |
|
301 | + { |
|
302 | + return $this->version; |
|
303 | + } |
|
304 | 304 | } |
@@ -127,7 +127,7 @@ |
||
127 | 127 | */ |
128 | 128 | private function setApiVersion(int $api_version): void |
129 | 129 | { |
130 | - if (! in_array($api_version, $this->validApiVersions())) { |
|
130 | + if ( ! in_array($api_version, $this->validApiVersions())) { |
|
131 | 131 | throw new DomainException( |
132 | 132 | esc_html__( |
133 | 133 | 'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants', |
@@ -42,7 +42,7 @@ |
||
42 | 42 | && ! function_exists('json_basic_auth_handler') |
43 | 43 | && ! function_exists('json_basic_auth_error') |
44 | 44 | ) { |
45 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
45 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php'; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | } |
@@ -7,43 +7,43 @@ |
||
7 | 7 | class ThirdPartyPluginHandler |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @var RequestInterface $request |
|
12 | - */ |
|
13 | - private $request; |
|
14 | - |
|
15 | - |
|
16 | - /** |
|
17 | - * ThirdPartyPluginHandler constructor. |
|
18 | - * |
|
19 | - * @param RequestInterface $request |
|
20 | - */ |
|
21 | - public function __construct(RequestInterface $request) |
|
22 | - { |
|
23 | - $this->request = $request; |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - public function loadPlugins() |
|
28 | - { |
|
29 | - $this->wpApiBasicAuth(); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - private function wpApiBasicAuth() |
|
34 | - { |
|
35 | - // if the WP API basic auth plugin isn't already loaded, load it now. |
|
36 | - // We want it for mobile apps. Just include the entire plugin |
|
37 | - // also, don't load the basic auth when a plugin is getting activated, because |
|
38 | - // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
39 | - // and causes a fatal error |
|
40 | - if ( |
|
41 | - ($this->request->isWordPressApi() || $this->request->isApi()) |
|
42 | - && ! $this->request->isActivation() |
|
43 | - && ! function_exists('json_basic_auth_handler') |
|
44 | - && ! function_exists('json_basic_auth_error') |
|
45 | - ) { |
|
46 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
47 | - } |
|
48 | - } |
|
10 | + /** |
|
11 | + * @var RequestInterface $request |
|
12 | + */ |
|
13 | + private $request; |
|
14 | + |
|
15 | + |
|
16 | + /** |
|
17 | + * ThirdPartyPluginHandler constructor. |
|
18 | + * |
|
19 | + * @param RequestInterface $request |
|
20 | + */ |
|
21 | + public function __construct(RequestInterface $request) |
|
22 | + { |
|
23 | + $this->request = $request; |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + public function loadPlugins() |
|
28 | + { |
|
29 | + $this->wpApiBasicAuth(); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + private function wpApiBasicAuth() |
|
34 | + { |
|
35 | + // if the WP API basic auth plugin isn't already loaded, load it now. |
|
36 | + // We want it for mobile apps. Just include the entire plugin |
|
37 | + // also, don't load the basic auth when a plugin is getting activated, because |
|
38 | + // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
39 | + // and causes a fatal error |
|
40 | + if ( |
|
41 | + ($this->request->isWordPressApi() || $this->request->isApi()) |
|
42 | + && ! $this->request->isActivation() |
|
43 | + && ! function_exists('json_basic_auth_handler') |
|
44 | + && ! function_exists('json_basic_auth_error') |
|
45 | + ) { |
|
46 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -5,95 +5,95 @@ |
||
5 | 5 | class LegacyModelApi |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @var string path to EE_* entity classes |
|
10 | - */ |
|
11 | - private $entity_classes; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var string path to EEM_* entity model classes |
|
15 | - */ |
|
16 | - private $entity_models; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var string path to EEE_* entity class extensions |
|
20 | - */ |
|
21 | - private $entity_class_extensions; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string path to EEME_* entity model class extensions |
|
25 | - */ |
|
26 | - private $entity_model_extensions; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function entityClasses(): string |
|
33 | - { |
|
34 | - return $this->entity_classes; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string $entity_classes |
|
40 | - */ |
|
41 | - public function addEntityClasses(string $entity_classes): void |
|
42 | - { |
|
43 | - $this->entity_classes = $entity_classes; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function entityModels(): string |
|
51 | - { |
|
52 | - return $this->entity_models; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $entity_models |
|
58 | - */ |
|
59 | - public function addEntityModels(string $entity_models): void |
|
60 | - { |
|
61 | - $this->entity_models = $entity_models; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function entityClassExtensions(): string |
|
69 | - { |
|
70 | - return $this->entity_class_extensions; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @param string $entity_class_extensions |
|
76 | - */ |
|
77 | - public function addEntityClassExtensions(string $entity_class_extensions): void |
|
78 | - { |
|
79 | - $this->entity_class_extensions = $entity_class_extensions; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function entityModelExtensions(): string |
|
87 | - { |
|
88 | - return $this->entity_model_extensions; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param string $entity_model_extensions |
|
94 | - */ |
|
95 | - public function addEntityModelExtensions(string $entity_model_extensions): void |
|
96 | - { |
|
97 | - $this->entity_model_extensions = $entity_model_extensions; |
|
98 | - } |
|
8 | + /** |
|
9 | + * @var string path to EE_* entity classes |
|
10 | + */ |
|
11 | + private $entity_classes; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var string path to EEM_* entity model classes |
|
15 | + */ |
|
16 | + private $entity_models; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var string path to EEE_* entity class extensions |
|
20 | + */ |
|
21 | + private $entity_class_extensions; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string path to EEME_* entity model class extensions |
|
25 | + */ |
|
26 | + private $entity_model_extensions; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function entityClasses(): string |
|
33 | + { |
|
34 | + return $this->entity_classes; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string $entity_classes |
|
40 | + */ |
|
41 | + public function addEntityClasses(string $entity_classes): void |
|
42 | + { |
|
43 | + $this->entity_classes = $entity_classes; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function entityModels(): string |
|
51 | + { |
|
52 | + return $this->entity_models; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $entity_models |
|
58 | + */ |
|
59 | + public function addEntityModels(string $entity_models): void |
|
60 | + { |
|
61 | + $this->entity_models = $entity_models; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function entityClassExtensions(): string |
|
69 | + { |
|
70 | + return $this->entity_class_extensions; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @param string $entity_class_extensions |
|
76 | + */ |
|
77 | + public function addEntityClassExtensions(string $entity_class_extensions): void |
|
78 | + { |
|
79 | + $this->entity_class_extensions = $entity_class_extensions; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function entityModelExtensions(): string |
|
87 | + { |
|
88 | + return $this->entity_model_extensions; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param string $entity_model_extensions |
|
94 | + */ |
|
95 | + public function addEntityModelExtensions(string $entity_model_extensions): void |
|
96 | + { |
|
97 | + $this->entity_model_extensions = $entity_model_extensions; |
|
98 | + } |
|
99 | 99 | } |
@@ -8,26 +8,26 @@ |
||
8 | 8 | |
9 | 9 | class RegisterAddon |
10 | 10 | { |
11 | - /** |
|
12 | - * @param AddonApiV1 $addon |
|
13 | - * @throws EE_Error |
|
14 | - */ |
|
15 | - public function register(AddonApiV1 $addon) |
|
16 | - { |
|
17 | - EE_Register_Addon::register( |
|
18 | - $addon->fqcn(), |
|
19 | - [ |
|
20 | - 'version' => $addon->version(), |
|
21 | - 'plugin_slug' => $addon->slug(), |
|
22 | - 'min_core_version' => $addon->minCoreVersion(), |
|
23 | - 'min_wp_version' => $addon->minWpVersion(), |
|
24 | - 'main_file_path' => $addon->mainFile(), |
|
25 | - 'dms_paths' => [$addon->dataMigrationScripts()], |
|
26 | - 'class_paths' => [$addon->entityClasses()], |
|
27 | - 'model_paths' => [$addon->entityModels()], |
|
28 | - 'class_extension_paths' => [$addon->entityClassExtensions()], |
|
29 | - 'model_extension_paths' => [$addon->entityModelExtensions()], |
|
30 | - ] |
|
31 | - ); |
|
32 | - } |
|
11 | + /** |
|
12 | + * @param AddonApiV1 $addon |
|
13 | + * @throws EE_Error |
|
14 | + */ |
|
15 | + public function register(AddonApiV1 $addon) |
|
16 | + { |
|
17 | + EE_Register_Addon::register( |
|
18 | + $addon->fqcn(), |
|
19 | + [ |
|
20 | + 'version' => $addon->version(), |
|
21 | + 'plugin_slug' => $addon->slug(), |
|
22 | + 'min_core_version' => $addon->minCoreVersion(), |
|
23 | + 'min_wp_version' => $addon->minWpVersion(), |
|
24 | + 'main_file_path' => $addon->mainFile(), |
|
25 | + 'dms_paths' => [$addon->dataMigrationScripts()], |
|
26 | + 'class_paths' => [$addon->entityClasses()], |
|
27 | + 'model_paths' => [$addon->entityModels()], |
|
28 | + 'class_extension_paths' => [$addon->entityClassExtensions()], |
|
29 | + 'model_extension_paths' => [$addon->entityModelExtensions()], |
|
30 | + ] |
|
31 | + ); |
|
32 | + } |
|
33 | 33 | } |
@@ -7,135 +7,135 @@ |
||
7 | 7 | class AddonApi extends AddonApiVersion |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @var DataMigrationApi |
|
12 | - */ |
|
13 | - private $data_migration_api; |
|
14 | - |
|
15 | - /** |
|
16 | - * @var LegacyModelApi |
|
17 | - */ |
|
18 | - private $legacy_model_api; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * Bootstrap constructor. |
|
23 | - * |
|
24 | - * @param string $slug |
|
25 | - * @param string $name |
|
26 | - * @param string $namespace |
|
27 | - * @param string $version |
|
28 | - * @param string $min_core_version |
|
29 | - * @param string $main_file |
|
30 | - */ |
|
31 | - public function __construct( |
|
32 | - string $slug, |
|
33 | - string $name, |
|
34 | - string $namespace, |
|
35 | - string $version, |
|
36 | - string $min_core_version, |
|
37 | - string $main_file |
|
38 | - ) { |
|
39 | - parent::__construct( |
|
40 | - $slug, |
|
41 | - $name, |
|
42 | - $namespace, |
|
43 | - $version, |
|
44 | - $min_core_version, |
|
45 | - $main_file, |
|
46 | - AddonApiVersion::V1 |
|
47 | - ); |
|
48 | - $this->legacy_model_api = new LegacyModelApi(); |
|
49 | - $this->data_migration_api = new DataMigrationApi(); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function dataMigrationScripts(): string |
|
57 | - { |
|
58 | - return $this->data_migration_api->dataMigrationScripts(); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param string $data_migration_scripts |
|
64 | - */ |
|
65 | - public function addDataMigrationScripts(string $data_migration_scripts): void |
|
66 | - { |
|
67 | - $this->data_migration_api->addDataMigrationScripts($data_migration_scripts); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function entityClasses(): string |
|
75 | - { |
|
76 | - return $this->legacy_model_api->entityClasses(); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @param string $entity_classes |
|
82 | - */ |
|
83 | - public function addEntityClasses(string $entity_classes): void |
|
84 | - { |
|
85 | - $this->legacy_model_api->addEntityClasses($entity_classes); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function entityModels(): string |
|
93 | - { |
|
94 | - return $this->legacy_model_api->entityModels(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $entity_models |
|
100 | - */ |
|
101 | - public function addEntityModels(string $entity_models): void |
|
102 | - { |
|
103 | - $this->legacy_model_api->addEntityModels($entity_models); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function entityClassExtensions(): string |
|
111 | - { |
|
112 | - return $this->legacy_model_api->entityClassExtensions(); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @param string $entity_class_extensions |
|
118 | - */ |
|
119 | - public function addEntityClassExtensions(string $entity_class_extensions): void |
|
120 | - { |
|
121 | - $this->legacy_model_api->addEntityClassExtensions($entity_class_extensions); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function entityModelExtensions(): string |
|
129 | - { |
|
130 | - return $this->legacy_model_api->entityModelExtensions(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param string $entity_model_extensions |
|
136 | - */ |
|
137 | - public function addEntityModelExtensions(string $entity_model_extensions): void |
|
138 | - { |
|
139 | - $this->legacy_model_api->addEntityModelExtensions($entity_model_extensions); |
|
140 | - } |
|
10 | + /** |
|
11 | + * @var DataMigrationApi |
|
12 | + */ |
|
13 | + private $data_migration_api; |
|
14 | + |
|
15 | + /** |
|
16 | + * @var LegacyModelApi |
|
17 | + */ |
|
18 | + private $legacy_model_api; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * Bootstrap constructor. |
|
23 | + * |
|
24 | + * @param string $slug |
|
25 | + * @param string $name |
|
26 | + * @param string $namespace |
|
27 | + * @param string $version |
|
28 | + * @param string $min_core_version |
|
29 | + * @param string $main_file |
|
30 | + */ |
|
31 | + public function __construct( |
|
32 | + string $slug, |
|
33 | + string $name, |
|
34 | + string $namespace, |
|
35 | + string $version, |
|
36 | + string $min_core_version, |
|
37 | + string $main_file |
|
38 | + ) { |
|
39 | + parent::__construct( |
|
40 | + $slug, |
|
41 | + $name, |
|
42 | + $namespace, |
|
43 | + $version, |
|
44 | + $min_core_version, |
|
45 | + $main_file, |
|
46 | + AddonApiVersion::V1 |
|
47 | + ); |
|
48 | + $this->legacy_model_api = new LegacyModelApi(); |
|
49 | + $this->data_migration_api = new DataMigrationApi(); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function dataMigrationScripts(): string |
|
57 | + { |
|
58 | + return $this->data_migration_api->dataMigrationScripts(); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param string $data_migration_scripts |
|
64 | + */ |
|
65 | + public function addDataMigrationScripts(string $data_migration_scripts): void |
|
66 | + { |
|
67 | + $this->data_migration_api->addDataMigrationScripts($data_migration_scripts); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function entityClasses(): string |
|
75 | + { |
|
76 | + return $this->legacy_model_api->entityClasses(); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @param string $entity_classes |
|
82 | + */ |
|
83 | + public function addEntityClasses(string $entity_classes): void |
|
84 | + { |
|
85 | + $this->legacy_model_api->addEntityClasses($entity_classes); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function entityModels(): string |
|
93 | + { |
|
94 | + return $this->legacy_model_api->entityModels(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $entity_models |
|
100 | + */ |
|
101 | + public function addEntityModels(string $entity_models): void |
|
102 | + { |
|
103 | + $this->legacy_model_api->addEntityModels($entity_models); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function entityClassExtensions(): string |
|
111 | + { |
|
112 | + return $this->legacy_model_api->entityClassExtensions(); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @param string $entity_class_extensions |
|
118 | + */ |
|
119 | + public function addEntityClassExtensions(string $entity_class_extensions): void |
|
120 | + { |
|
121 | + $this->legacy_model_api->addEntityClassExtensions($entity_class_extensions); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function entityModelExtensions(): string |
|
129 | + { |
|
130 | + return $this->legacy_model_api->entityModelExtensions(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param string $entity_model_extensions |
|
136 | + */ |
|
137 | + public function addEntityModelExtensions(string $entity_model_extensions): void |
|
138 | + { |
|
139 | + $this->legacy_model_api->addEntityModelExtensions($entity_model_extensions); |
|
140 | + } |
|
141 | 141 | } |