1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Framework\Containers\Modules\DataStructures\Module; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Spl\Info\SplClassInfo; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Controller |
22
|
|
|
* @package O2System\Framework\Containers\Modules\DataStructures\Module |
23
|
|
|
*/ |
24
|
|
|
class Controller extends SplClassInfo |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Controller::$methods |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
public $methods = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Controller::$namespace |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
public $namespace; |
39
|
|
|
|
40
|
|
|
// ------------------------------------------------------------------------ |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Controller::__construct |
44
|
|
|
* |
45
|
|
|
* @param string $className |
46
|
|
|
*/ |
47
|
|
|
public function __construct($className) |
48
|
|
|
{ |
49
|
|
|
parent::__construct($className); |
50
|
|
|
|
51
|
|
|
if ( ! empty($this->name)) { |
52
|
|
|
$this->namespace = get_namespace($className); |
53
|
|
|
|
54
|
|
|
$nameParts = explode('\\', $this->name); |
55
|
|
|
|
56
|
|
|
$segments = []; |
57
|
|
|
foreach ($nameParts as $namePart) { |
58
|
|
|
if ( ! in_array(strtolower($namePart), [ |
59
|
|
|
'app', |
60
|
|
|
'apps', |
61
|
|
|
'modules', |
62
|
|
|
'components', |
63
|
|
|
'plugins', |
64
|
|
|
'controllers', |
65
|
|
|
])) { |
66
|
|
|
$namePart = dash($namePart); |
67
|
|
|
|
68
|
|
|
if ( ! in_array($namePart, $segments)) { |
69
|
|
|
array_push($segments, $namePart); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ($methods = $this->getMethods(\ReflectionMethod::IS_PUBLIC)) { |
75
|
|
|
foreach ($methods as $method) { |
76
|
|
|
if (strpos($method->name, '__') === false and ! in_array($method->name, |
77
|
|
|
[ |
78
|
|
|
'route', |
79
|
|
|
'getClassInfo', |
80
|
|
|
'form', |
81
|
|
|
'add', |
82
|
|
|
'add-new', |
83
|
|
|
'edit', |
84
|
|
|
'create', |
85
|
|
|
'read', |
86
|
|
|
'update', |
87
|
|
|
'delete', |
88
|
|
|
'open', |
89
|
|
|
'download', |
90
|
|
|
'detail', |
91
|
|
|
'overview', |
92
|
|
|
'view', |
93
|
|
|
'settings', |
94
|
|
|
'setting', |
95
|
|
|
'sendError', |
96
|
|
|
'sendPayload' |
97
|
|
|
])) { |
98
|
|
|
$methodSegments = $segments; |
99
|
|
|
|
100
|
|
|
$method->segment = dash($method->name); |
|
|
|
|
101
|
|
|
|
102
|
|
|
if ( ! in_array($method->name, $methodSegments) and $method->name !== 'index') { |
103
|
|
|
array_push($methodSegments, dash($method->name)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$method->segments = implode('/', $methodSegments); |
|
|
|
|
107
|
|
|
$method->hash = md5($method->segments); |
|
|
|
|
108
|
|
|
|
109
|
|
|
$this->methods[$method->segment] = $method; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if(empty($this->methods) and $this->hasMethod('route')) { |
115
|
|
|
$method = $this->getMethod('route'); |
116
|
|
|
$method->segment = dash($method->name); |
117
|
|
|
$method->segments = implode('/', $segments); |
118
|
|
|
$method->hash = md5($method->segments); |
119
|
|
|
$this->methods[$method->segment] = $method; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} |