-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathWindCommandRouter.php
More file actions
101 lines (94 loc) · 2.72 KB
/
WindCommandRouter.php
File metadata and controls
101 lines (94 loc) · 2.72 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
Wind::import('WIND:router.AbstractWindRouter');
/**
* 命令行路由,默认路由规则 php index.php [-m default] [-c index] [-a run] [-p id1 id2] [--help]
*
* @author Shi Long <[email protected]>
* @copyright ©2003-2103 phpwind.com
* @license http://www.windframework.com
* @version $Id$
* @package command
*/
class WindCommandRouter extends AbstractWindRouter {
protected $moduleKey = '-m,module,--module';
protected $controllerKey = '-c,controller,--controller';
protected $actionKey = '-a,action,--action';
protected $helpKey = '-h,help,--help';
protected $paramKey = '-p,param,--param';
protected $help = false;
protected $cmd = '';
/**
* @var WindCommandRequest
*/
private $request = null;
/* (non-PHPdoc)
* @see AbstractWindRouter::route()
*/
public function route($request) {
$this->request = $request;
$this->_action = $this->action;
$this->_controller = $this->controller;
$this->_module = $this->module;
if (!empty($this->_config['routes'])) {
$params = $this->getHandler()->handle($request);
$this->setParams($params, $request);
} else {
$args = $request->getRequest('argv', array());
$this->cmd = $args[0];
$_count = count($args);
for ($i = 1; $i < $_count; $i++) {
if (in_array($args[$i], explode(',', $this->helpKey))) {
$this->help = true;
} elseif (in_array($args[$i], explode(',', $this->moduleKey))) {
$this->module = $args[++$i];
} elseif (in_array($args[$i], explode(',', $this->controllerKey))) {
$this->controller = $args[++$i];
} elseif (in_array($args[$i], explode(',', $this->actionKey))) {
$this->action = $args[++$i];
} elseif (in_array($args[$i], explode(',', $this->paramKey))) {
$_SERVER['argv'] = array_slice($args, $i + 1);
break;
}
}
}
}
/* (non-PHPdoc)
* @see AbstractWindRouter::assemble()
*/
public function assemble($action, $args = array(), $route = '') {
return '';
}
/* (non-PHPdoc)
* @see AbstractWindRouter::setParams()
*/
protected function setParams($params, $request) {
/* @var $request WindCommandRequest */
$_SERVER['argv'] = isset($params[$this->paramKey]) ? $params[$this->paramKey] : array();
isset($params[$this->moduleKey]) && $this->setModule($params[$this->moduleKey]);
isset($params[$this->controllerKey]) && $this->setController($params[$this->controllerKey]);
isset($params[$this->actionKey]) && $this->setAction($params[$this->actionKey]);
}
/**
* 是否是请求帮助
*
* @return boolean
*/
public function isHelp() {
return $this->help;
}
/**
* 返回当前命令
*
* @return string
*/
public function getCmd() {
return $this->cmd;
}
/**
* @return string
*/
public function getParamKey() {
return $this->paramKey;
}
}
?>