-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclass.models-loader.php
More file actions
41 lines (34 loc) · 958 Bytes
/
Copy pathclass.models-loader.php
File metadata and controls
41 lines (34 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace WPS;
class ModelsLoader extends \WPS {
public static function init() {
if(file_exists(WPS_INCLUDES_DIR . '/CMB2/init.php')) {
require_once(WPS_INCLUDES_DIR . '/CMB2/init.php');
}
add_action('cmb2_init', [__CLASS__, 'load_models']);
}
public static function load_models() {
if(file_exists(WPS_MODELS_DIR)) {
self::load_files_within(
WPS_MODELS_DIR,
'WPS\ModelRecursiveFilterIterator',
'WPS\ModelsLoader::loader_callback'
);
}
}
public static function loader_callback($file) {
$filter_filename = str_replace(
['cmb2.', 'model.', '.php'],
'',
$file->getFilename()
);
$class_name = implode(
'-',
array_map('ucfirst', explode('-', $filter_filename))
);
if(class_exists($class_name)) new $class_name;
}
}
class ModelRecursiveFilterIterator extends FilterIterator {
protected $file_prefixes = ['model.', 'cmb2.'];
}