-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mfwModules.php
66 lines (53 loc) · 1.46 KB
/
mfwModules.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
<?php
abstract class mfwModules {
abstract protected static function rootdir();
protected static function getActionClassNames($module,$action)
{
$ret = array();
$classname = "{$action}Action";
$ret["{$classname}.php"] = $classname;
if(preg_match('/^(.[^A-Z_]*)([A-Z_][^A-Z]*)?/',$action,$match)){
if(isset($match[2])){
$classname = "{$match[1]}{$match[2]}Actions";
$ret["{$classname}.php"] = $classname;
}
if(isset($match[1])){
$classname = "{$match[1]}Actions";
$ret["{$classname}.php"] = $classname;
}
}
$classname = "{$module}Actions";
$ret['actions.php'] = $classname;
return $ret;
}
protected static function getActionClass($module,$action)
{
$classnames = static::getActionClassNames($module,$action);
$actionsdir = static::rootdir()."/{$module}/actions";
$class = null;
foreach($classnames as $filename => $classname){
$path = "{$actionsdir}/{$filename}";
if(file_exists($path)){
require_once $path;
$class = new $classname($module,$action);
break;
}
}
return $class;
}
protected static function executeAction($module,$action)
{
$class = static::getActionClass($module,$action);
if($class===null){
return array(array(mfwActions::HTTP_404_NOTFOUND),'404 Not Found');
}
if(($err=$class->initialize())){
return $err;
}
$funcname= 'execute'.ucfirst($action);
if(!method_exists($class,$funcname)){
$funcname = 'executeDefaultAction';
}
return $class->$funcname();
}
}