-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole_init.php
43 lines (35 loc) · 1002 Bytes
/
console_init.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
<?php
class ConsoleApplication {
public static $config;
public static $r;
public static $instance;
public $namespace = 'Command\\Controller\\';
private function __construct(){
}
public static function Init($config){
if(is_null(self::$instance)){
self::$instance = new ConsoleApplication();
}
self::$instance->module = $config['module'];
return self::$instance;
}
public function run(){
$argv = $_SERVER['argv'] ;
$consoleName = $argv[0];
$router = $argv[1];
unset($argv[0],$argv[1]);
$params = $argv;
$router = explode("/", $router);
$controllerName = str_replace(' ', '', ucwords(implode(' ', explode('-', $router[0]))));
$action = 'action'.str_replace(' ', '', ucwords(implode(' ', explode('-', $router[1]))));
$controllerName = $this->namespace.$controllerName;
$controller = new $controllerName;
try{
return call_user_func_array(array($controller, $action), $params);
}catch (Exception $e){
echo $e->getMessage();
}
die;
}
}
?>