-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move input flag class to Flag namespace
- Loading branch information
Showing
11 changed files
with
130 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php declare(strict_types=1); | ||
|
||
|
||
namespace Inhere\Console\Handler; | ||
|
||
use Inhere\Console\Command; | ||
use Inhere\Console\IO\Input; | ||
use Inhere\Console\IO\Output; | ||
|
||
/** | ||
* Class CallableCommand - wrap an callable as Command | ||
* | ||
* @package Inhere\Console\Handler | ||
*/ | ||
class CallableCommand extends Command | ||
{ | ||
/** | ||
* @var callable | ||
*/ | ||
private $callable; | ||
|
||
// /** | ||
// * @param callable $cb | ||
// * | ||
// * @return static | ||
// */ | ||
// public static function wrap(callable $cb): self | ||
// { | ||
// return (new self())->setCallable($cb); | ||
// } | ||
|
||
/** | ||
* @param callable $callable | ||
* | ||
* @return CallableCommand | ||
*/ | ||
public function setCallable(callable $callable): self | ||
{ | ||
$this->callable = $callable; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Do execute command | ||
* | ||
* @param Input $input | ||
* @param Output $output | ||
* | ||
* @return int|mixed | ||
*/ | ||
protected function execute($input, $output) | ||
{ | ||
if (!$call = $this->callable) { | ||
throw new \BadMethodCallException('The callable property is empty'); | ||
} | ||
|
||
// call custom callable | ||
return $call($input, $output); | ||
} | ||
} |