Skip to content

Commit 94fec5c

Browse files
committed
some modify
1 parent 8d7f2fa commit 94fec5c

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

src/io/Input.php

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ class Input
1919
*/
2020
protected $inputStream = STDIN;
2121

22+
/**
23+
* @var string
24+
*/
25+
private $fullScript;
26+
2227
/**
2328
* the script name
2429
* e.g `./bin/app` OR `bin/cli.php`
2530
* @var string
2631
*/
27-
private $scriptName = '';
32+
private $script;
2833

2934
/**
3035
* the script name
31-
* e.g `image/packTask` OR `start`
36+
* e.g `start` OR `start`
3237
* @var string
3338
*/
34-
private $command = '';
39+
private $command;
3540

3641
/**
3742
* Input data
@@ -51,7 +56,7 @@ class Input
5156
*/
5257
public function __construct($fillToGlobal = false)
5358
{
54-
[$this->scriptName, $this->command, $this->args, $this->opts] = self::parseGlobalArgv($fillToGlobal);
59+
[$this->script, $this->command, $this->args, $this->opts] = self::parseGlobalArgv($fillToGlobal);
5560
}
5661

5762
/**
@@ -237,25 +242,33 @@ public function getBoolOpt(string $name, $default = false)
237242
/**
238243
* @return string
239244
*/
240-
public function getScript(): string
245+
public function getFullScript(): string
241246
{
242-
return $this->scriptName;
247+
return $this->fullScript;
243248
}
244249

245250
/**
246251
* @return string
247252
*/
248253
public function getScriptName(): string
249254
{
250-
return $this->scriptName;
255+
return $this->script;
251256
}
252257

253258
/**
254-
* @param string $scriptName
259+
* @return string
255260
*/
256-
public function setScriptName(string $scriptName)
261+
public function getScript(): string
257262
{
258-
$this->scriptName = $scriptName;
263+
return $this->script;
264+
}
265+
266+
/**
267+
* @param string $script
268+
*/
269+
public function setScript(string $script)
270+
{
271+
$this->script = $script;
259272
}
260273

261274
/**
@@ -324,23 +337,18 @@ public function getInputStream()
324337
*/
325338
public static function parseGlobalArgv($fillToGlobal = false)
326339
{
327-
// eg: `./bin/app image/packTask name=john city -s=test --page=23 -d -rf --debug`
328-
// eg: `php cli.php image/packTask name=john city -s=test --page=23 -d -rf --debug`
340+
// eg: `./bin/app server name=john city -s=test --page=23 -d -rf --debug`
341+
// eg: `php cli.php server name=john city -s=test --page=23 -d -rf --debug`
329342
global $argv;
330343

331344
$tmp = $argv;
332-
$command = '';
333-
$scriptName = array_shift($tmp);
334-
335-
// collect command `image/packTask`
336-
if (isset($tmp[0]) && $tmp[0]{0} !== '-' && (false === strpos($tmp[0], '='))) {
337-
$command = trim(array_shift($tmp), '/');
338-
}
345+
$fullScript = implode(' ', $tmp);
346+
$script = array_shift($tmp);
339347

340348
$args = $opts = [];
341349

342350
// parse query params
343-
// `./bin/app image/packTask start name=john city=chengdu -s=test --page=23 -d -rf --debug --task=off`
351+
// `./bin/app server start name=john city=chengdu -s=test --page=23 -d -rf --debug --task=off`
344352
// parse to
345353
// $args = [ 'name' => 'john', 0 => 'start', 'city' => 'chengdu' ];
346354
// $opts = [ 'd' => true, 'f' => true, 'r' => true, 's' => 'test', 'debug' => true, 'task' => false ]
@@ -361,8 +369,11 @@ public static function parseGlobalArgv($fillToGlobal = false)
361369
}
362370
}
363371

372+
// collect command `server`
373+
$command = isset($args[0]) ? array_shift($args) : '';
374+
364375
unset($tmp);
365-
return [$scriptName, $command, $args, $opts];
376+
return [$fullScript, $script, $command, $args, $opts];
366377
}
367378

368379
/**

0 commit comments

Comments
 (0)