Skip to content

Commit 37b71cf

Browse files
committed
update some arg bind logic
1 parent 75646b2 commit 37b71cf

File tree

11 files changed

+846
-722
lines changed

11 files changed

+846
-722
lines changed

examples/alone

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require dirname(__DIR__) . '/test/boot.php';
1515

1616
$input = new Input();
1717
$ctrl = new HomeController($input, new Output());
18-
$ctrl->setExecutionAlone();
18+
$ctrl->setDetached();
1919

2020
try {
2121
exit($ctrl->run($input->getCommand()));

src/AbstractHandler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,14 @@ public function isAttached(): bool
851851
return $this->attached;
852852
}
853853

854+
/**
855+
* @return bool
856+
*/
857+
public function isDetached(): bool
858+
{
859+
return $this->attached === false;
860+
}
861+
854862
/**
855863
* @param bool $attached
856864
*/
@@ -859,6 +867,14 @@ public function setAttached(bool $attached): void
859867
$this->attached = $attached;
860868
}
861869

870+
/**
871+
* Detached running
872+
*/
873+
public function setDetached(): void
874+
{
875+
$this->attached = false;
876+
}
877+
862878
/**
863879
* @return string
864880
*/

src/Application.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected function getFileFilter(): callable
257257
* @throws ReflectionException
258258
* @throws InvalidArgumentException
259259
*/
260-
public function dispatch(string $name, bool $standAlone = false)
260+
public function dispatch(string $name, bool $detachedRun = false)
261261
{
262262
$this->logf(Console::VERB_DEBUG, 'begin dispatch command: %s', $name);
263263

@@ -287,23 +287,25 @@ public function dispatch(string $name, bool $standAlone = false)
287287
return 2;
288288
}
289289

290+
$cmdOptions = $info['options'];
291+
290292
// save command ID
291293
$this->input->setCommandId($info['cmdId']);
292294

293295
// is command
294296
if ($info['type'] === Router::TYPE_SINGLE) {
295-
return $this->runCommand($info['name'], $info['handler'], $info['options']);
297+
return $this->runCommand($info['name'], $info['handler'], $cmdOptions);
296298
}
297299

298300
// is controller/group
299-
return $this->runAction($info['group'], $info['action'], $info['handler'], $info['options'], $standAlone);
301+
return $this->runAction($info['group'], $info['action'], $info['handler'], $cmdOptions, $detachedRun);
300302
}
301303

302304
/**
303305
* run a independent command
304306
*
305307
* @param string $name Command name
306-
* @param Closure|string $handler Command class
308+
* @param Closure|string $handler Command class or handler func
307309
* @param array $options
308310
*
309311
* @return mixed
@@ -346,12 +348,12 @@ protected function runCommand(string $name, $handler, array $options)
346348
* @param string $action Command method, no suffix
347349
* @param mixed $handler The controller class or object
348350
* @param array $options
349-
* @param bool $standAlone
351+
* @param bool $detachedRun
350352
*
351353
* @return mixed
352354
* @throws ReflectionException
353355
*/
354-
protected function runAction(string $group, string $action, $handler, array $options, bool $standAlone = false)
356+
protected function runAction(string $group, string $action, $handler, array $options, bool $detachedRun = false)
355357
{
356358
/** @var Controller $handler */
357359
if (is_string($handler)) {
@@ -372,15 +374,18 @@ protected function runAction(string $group, string $action, $handler, array $opt
372374
);
373375
}
374376

377+
// force set name and description
375378
$handler::setName($group);
376-
377379
if ($desc = $options['description'] ?? '') {
378380
$handler::setDescription($desc);
379381
}
380382

381383
$handler->setApp($this);
382384
$handler->setDelimiter($this->delimiter);
383-
$handler->setExecutionAlone($standAlone);
385+
386+
if ($detachedRun) {
387+
$handler->setDetached();
388+
}
384389

385390
return $handler->run($action);
386391
}

0 commit comments

Comments
 (0)