-
Notifications
You must be signed in to change notification settings - Fork 11
/
DirectoryModelLoader.php
65 lines (53 loc) · 1.59 KB
/
DirectoryModelLoader.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace MABI;
include_once __DIR__ . '/ModelLoader.php';
include_once __DIR__ . '/Utilities.php';
/**
* todo: docs
*/
class DirectoryModelLoader extends ModelLoader {
protected $directory;
protected $namespace;
/**
* @var \MABI\Extension
*/
protected $extension;
/**
* @var string[]
*/
protected $modelClasses = array();
protected $modelClassFiles = array();
/**
* todo: docs
*
* @param $directory string
* @param $extension \MABI\Extension
* @param $namespace string|null
*/
public function __construct($directory, $extension, $namespace = NULL) {
$this->directory = $directory;
$this->namespace = $namespace;
$this->extension = $extension;
if (($systemCache = $this->extension->getApp()->getCacheRepository('system')) != NULL &&
is_array($modelClassFiles = $systemCache->get($this->directory . '::fileList'))
) {
$this->modelClassFiles = $modelClassFiles;
}
else {
// Make sure all PHP files in the directory are included
$this->modelClassFiles = DirectoryHelper::directoryToArray($this->directory, TRUE, '.php');
if ($systemCache != NULL) {
$systemCache->forever($this->directory . '::fileList', $this->modelClassFiles);
}
}
foreach ($this->modelClassFiles as $modelClassFile) {
include_once $modelClassFile;
}
}
public function loadModels() {
foreach ($this->modelClassFiles as $modelClassFile) {
$this->modelClasses[] = ReflectionHelper::createClassName($this->namespace, basename($modelClassFile, '.php'));
}
return $this->modelClasses;
}
}