-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.php
More file actions
executable file
·105 lines (93 loc) · 2.57 KB
/
cli.php
File metadata and controls
executable file
·105 lines (93 loc) · 2.57 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
102
103
104
105
<?php
namespace PMVC\PlugIn\cli;
use PMVC\NamespaceAdapter;
use PMVC\PlugIn;
use PMVC\RouterInterface;
${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\cli';
\PMVC\l(__DIR__ . '/src/ConsoleColor2');
\PMVC\initPlugIn(['controller' => null], true);
class cli extends PlugIn implements RouterInterface
{
private $_color;
public function getOptApp()
{
$opts = $this->getopt();
if (empty($opts[1])) {
$appsFolder = \PMVC\lastSlash(
\PMVC\plug('controller')->getAppsFolder()
);
$pwd = getcwd();
$start = strpos($pwd, $appsFolder);
if (0 === $start) {
$sApp = explode('/', substr($pwd, strlen($appsFolder)));
if (!empty($sApp[0])) {
$app = [$sApp[0]];
}
}
if (empty($app)) {
return;
}
} else {
$app = explode(':', $opts[1]);
}
return compact('opts', 'app');
}
public function onMapRequest()
{
$optApp = $this->getOptApp();
if (empty($optApp)) {
return;
}
extract(\PMVC\assign(['opts', 'app'], $optApp));
$controller = \PMVC\plug('controller');
$request = $controller->getRequest();
foreach ($opts as $k => $v) {
if (!is_numeric($k)) {
$request[$k] = $v;
} elseif ($k > 1) {
$request[] = $v;
}
}
if (isset($app[0])) {
$controller->setApp($app[0]);
}
if (isset($app[1])) {
$controller->setAppAction($app[1]);
}
}
public function init()
{
\PMVC\callPlugin('dispatcher', 'attach', [
$this,
\PMVC\Event\MAP_REQUEST,
]);
$this->_color = new ConsoleColor2();
$this->setDefaultAlias(new NamespaceAdapter('cli'));
}
public function color($color, $text)
{
if (is_array($text) || is_object($text)) {
$text = print_r($text, true);
}
$text = $this->_color->escape($text);
return $this->_color->convert($color . $text . '%n');
}
public function dump($text, $color = '%m')
{
echo $this->color($color, $text) . "\n";
}
public function stderr($str, $stream = STDERR)
{
fwrite($stream, $str);
}
// abstract function
public function buildCommand($path, $params)
{
}
public function processHeader(array $headers)
{
}
public function go($path, $isClientLocation = false)
{
}
}