-
Notifications
You must be signed in to change notification settings - Fork 11
/
DirectoryControllerLoader.php
83 lines (66 loc) · 2.07 KB
/
DirectoryControllerLoader.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace MABI;
include_once __DIR__ . '/Utilities.php';
include_once __DIR__ . '/ControllerLoader.php';
include_once __DIR__ . '/ModelController.php';
class DirectoryControllerLoader extends ControllerLoader {
/**
* @var \MABI\Extension
*/
protected $extension;
/**
* @var string
*/
protected $directory;
/**
* @var string
*/
protected $namespace = '';
/**
* @var string[]
*/
protected $controllerClasses = array();
/**
* @var string[]
*/
protected $overriddenModelClasses = array();
public function __construct($directory, $extension, $namespace = NULL) {
$this->extension = $extension;
$this->directory = $directory;
$this->namespace = empty($namespace) ? '' : $namespace;
if (($systemCache = $this->extension->getApp()->getCacheRepository('system')) != NULL &&
is_array($controllerClassFiles = $systemCache->get($this->directory . '::fileList'))
) {
}
else {
// Make sure all PHP files in the directory are included
$controllerClassFiles = DirectoryHelper::directoryToArray($this->directory, TRUE, '.php');
if ($systemCache != NULL) {
$systemCache->forever($this->directory . '::fileList', $controllerClassFiles);
}
}
foreach ($controllerClassFiles as $controllerClassFile) {
include_once $controllerClassFile;
$controllerClass = ReflectionHelper::createClassName($this->namespace, basename($controllerClassFile, '.php'));
$this->controllerClasses[] = $controllerClass;
$controller = new $controllerClass($this->extension);
$rclass = new \ReflectionClass($controller);
if ($rclass->isSubclassOf('\MABI\ModelController')) {
/**
* @var $controller \MABI\ModelController
*/
$this->overriddenModelClasses[] = $controller->getModelClass();
}
$this->controllers[] = $controller;
}
}
public function getOverriddenModelClasses() {
return $this->overriddenModelClasses;
}
/**
* @return Controller[]
*/
public function getControllers() {
return $this->controllers;
}
}