Skip to content

Commit 41b8b88

Browse files
committed
合并主干的功能更新和调整到 php5 分支
- 参数解析逻辑调整 - 功能更新调整 - 完善文档信息 - 其他调整
1 parent d1feb5a commit 41b8b88

17 files changed

+127
-124
lines changed

README_zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
编辑 `composer.json`,在 `require` 添加
2727

2828
```
29-
"inhere/console": "dev-master",
30-
// "inhere/console": "dev-php5", // for php5
29+
"inhere/console": "dev-php5",
30+
// "inhere/console": "dev-master", // for php7
3131
```
3232

3333
然后执行: `composer update`
@@ -68,7 +68,7 @@ $app->run();
6868

6969
然后在命令行里执行 `php examples/app`, 立即就可以看到如下输出了:
7070

71-
```bash
71+
```
7272
$ php examples/app
7373
Usage:
7474
examples/app [route|command] [arg1=value1 arg2=value ...] [-v|-h ...]

examples/HomeController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function downCommand()
198198
$url = $this->input->getArg('url');
199199

200200
if (!$url) {
201-
\inhere\console\utils\Show::error('Please input you want to downloaded file url, use: url=[url]', 1);
201+
$this->output->error('Please input you want to downloaded file url, use: url=[url]', 1);
202202
}
203203

204204
$saveAs = $this->input->getArg('saveAs');
@@ -211,7 +211,7 @@ public function downCommand()
211211
$goon = Interact::confirm("Now, will download $url to $saveAs, go on");
212212

213213
if (!$goon) {
214-
\inhere\console\utils\Show::notice('Quit download, Bye!');
214+
$this->output->notice('Quit download, Bye!');
215215

216216
return 0;
217217
}

examples/baks/OldInput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected static function parseOption($item, &$opts)
8585
// is a have value option. eg: `-s=test --page=23`
8686
if (strpos($item, '=')) {
8787
$item = trim($item, '-= ');
88-
[$name, $val] = explode('=', $item);
88+
list($name, $val) = explode('=', $item);
8989
$tVal = strtolower($val);
9090

9191
// check it is a bool value.
@@ -145,7 +145,7 @@ protected static function parseArgument($item, &$args)
145145

146146
// eg: `name=john`
147147
if (strpos($item, '=')) {
148-
[$name, $val] = explode('=', $item);
148+
list($name, $val) = explode('=', $item);
149149

150150
// is array. eg: `name=john name=tom`
151151
if (isset($args[$name])) {

src/AbstractApp.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function stop($code = 0)
154154
* @param string $controller The controller class
155155
* @return static
156156
*/
157-
public function controller(string $name, string $controller)
157+
public function controller($name, $controller)
158158
{
159159
if (!$name || !$controller) {
160160
throw new \InvalidArgumentException('Parameters are not allowed to is empty!');
@@ -187,7 +187,7 @@ public function controllers(array $controllers)
187187
* @param string|\Closure $handler
188188
* @return $this
189189
*/
190-
public function command(string $name, $handler)
190+
public function command($name, $handler)
191191
{
192192
if (!$name || !$handler) {
193193
throw new \InvalidArgumentException('Parameters are not allowed to is empty!');
@@ -214,7 +214,7 @@ public function commands(array $commands)
214214
/**
215215
* @return array
216216
*/
217-
public static function hooks(): array
217+
public static function hooks()
218218
{
219219
return array_keys(self::$hooks);
220220
}
@@ -223,7 +223,7 @@ public static function hooks(): array
223223
* @param $event
224224
* @param callable $handler
225225
*/
226-
public function on(string $event, callable $handler)
226+
public function on($event, callable $handler)
227227
{
228228
if (isset(self::$hooks[$event])) {
229229
self::$hooks[$event] = $handler;
@@ -233,7 +233,7 @@ public function on(string $event, callable $handler)
233233
/**
234234
* @return array
235235
*/
236-
public function getInternalCommands(): array
236+
public function getInternalCommands()
237237
{
238238
return $this->internalCommands;
239239
}
@@ -242,7 +242,7 @@ public function getInternalCommands(): array
242242
* @param $name
243243
* @return bool
244244
*/
245-
public function isInternalCommand(string $name): bool
245+
public function isInternalCommand($name)
246246
{
247247
return isset($this->internalCommands[$name]);
248248
}
@@ -278,7 +278,7 @@ public function config($name, $default = null)
278278
}
279279
}
280280

281-
return $this->config[$name] ?? $default;
281+
return isset($this->config[$name]) ? $this->config[$name] : $default;
282282
}
283283

284284
/**
@@ -296,7 +296,7 @@ public function setConfig(array $config)
296296
* get config
297297
* @return array
298298
*/
299-
public function getConfig(): array
299+
public function getConfig()
300300
{
301301
return $this->config;
302302
}
@@ -305,7 +305,7 @@ public function getConfig(): array
305305
* is Debug
306306
* @return boolean
307307
*/
308-
public function isDebug(): bool
308+
public function isDebug()
309309
{
310310
return (bool)$this->config['debug'];
311311
}
@@ -314,7 +314,7 @@ public function isDebug(): bool
314314
* @param $name
315315
* @param bool $isGroup
316316
*/
317-
protected function checkName(string $name, $isGroup = false)
317+
protected function checkName($name, $isGroup = false)
318318
{
319319
$pattern = $isGroup ? '/^[a-z][\w-]+$/' : '/^[a-z][\w-]*:?([a-z][\w-]+)?$/';
320320

src/AbstractCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,34 @@ protected function afterRun($action)
6262
/**
6363
* handle action/command runtime exception
6464
*
65-
* @param \Throwable $e
66-
* @throws \Throwable
65+
* @param \Exception $e
66+
* @throws \Exception
6767
*/
68-
protected function handleRuntimeException(\Throwable $e)
68+
protected function handleRuntimeException(\Exception $e)
6969
{
7070
throw $e;
7171
}
7272

7373
/**
7474
* @param string $name
7575
*/
76-
public function setName(string $name)
76+
public function setName($name)
7777
{
7878
$this->name = $name;
7979
}
8080

8181
/**
8282
* @return string
8383
*/
84-
public function getName(): string
84+
public function getName()
8585
{
8686
return $this->name;
8787
}
8888

8989
/**
9090
* @return array
9191
*/
92-
public static function getAllowTags(): array
92+
public static function getAllowTags()
9393
{
9494
return self::$allowTags;
9595
}

src/Controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ final protected function showCommandList()
190190
/**
191191
* @return string
192192
*/
193-
public function getDefaultAction(): string
193+
public function getDefaultAction()
194194
{
195195
return $this->defaultAction;
196196
}
@@ -206,7 +206,7 @@ public function setDefaultAction($defaultAction)
206206
/**
207207
* @return string
208208
*/
209-
public function getActionSuffix(): string
209+
public function getActionSuffix()
210210
{
211211
return $this->actionSuffix;
212212
}
@@ -274,7 +274,7 @@ protected function parseDocCommentTags($comment)
274274
* @param $comment
275275
* @return string
276276
*/
277-
protected function parseDocCommentSummary($comment): string
277+
protected function parseDocCommentSummary($comment)
278278
{
279279
$docLines = preg_split('~\R~u', $comment);
280280

@@ -291,7 +291,7 @@ protected function parseDocCommentSummary($comment): string
291291
* @param $comment
292292
* @return string
293293
*/
294-
protected function parseDocCommentDetail($comment): string
294+
protected function parseDocCommentDetail($comment)
295295
{
296296
$comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($comment, '/'))), "\r", '');
297297

src/Helper.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public static function spliceKeyValue(array $data, array $opts = [])
241241
* Returns true if the console is running on windows
242242
* @return boolean
243243
*/
244-
public static function isOnWindows(): bool
244+
public static function isOnWindows()
245245
{
246246
return DIRECTORY_SEPARATOR === '\\';
247247
}
@@ -346,25 +346,28 @@ public static function wrapText($text, $indent = 0, $width = 0)
346346

347347
/**
348348
* dump vars
349-
* @param array ...$args
350349
* @return string
351350
*/
352-
public static function dumpVar(...$args)
351+
public static function dumpVar()
353352
{
353+
$args = func_get_args();
354+
354355
ob_start();
355-
var_dump(...$args);
356+
foreach ($args as $arg) {
357+
print_r($arg);
358+
}
356359
$string = ob_get_clean();
357360

358361
return preg_replace("/=>\n\s+/", '=> ', $string);
359362
}
360363

361364
/**
362365
* print vars
363-
* @param array ...$args
364366
* @return string
365367
*/
366-
public static function printR(...$args)
368+
public static function printR()
367369
{
370+
$args = func_get_args();
368371
ob_start();
369372

370373
foreach ($args as $arg) {

0 commit comments

Comments
 (0)