carno-php /
console
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Based runner |
||
| 4 | * User: moyo |
||
| 5 | * Date: 2018/5/24 |
||
| 6 | * Time: 10:44 PM |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Carno\Console\Chips\Based; |
||
| 10 | |||
| 11 | use Carno\Console\Bootstrap; |
||
| 12 | use function Carno\Coroutine\defer; |
||
| 13 | use Throwable; |
||
| 14 | |||
| 15 | trait Runner |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var Bootstrap |
||
| 19 | */ |
||
| 20 | private $boots = null; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @return Bootstrap |
||
| 24 | */ |
||
| 25 | final protected function bootstrap() : Bootstrap |
||
| 26 | { |
||
| 27 | return $this->boots; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param Bootstrap $boot |
||
| 32 | * @return mixed |
||
| 33 | */ |
||
| 34 | final public function execute(Bootstrap $boot) |
||
| 35 | { |
||
| 36 | $this->boots = $boot; |
||
| 37 | |||
| 38 | yield defer(function ($e = null) use ($boot) { |
||
| 39 | if ($e instanceof Throwable) { |
||
| 40 | logger('console')->error('Application crashed', ['ec' => get_class($e), 'em' => $e->getMessage()]); |
||
| 41 | } |
||
| 42 | logger('console')->info('Application going to shutdown'); |
||
| 43 | $this->ready && yield $boot->app()->stopping()->perform(); |
||
| 44 | }); |
||
| 45 | |||
| 46 | $boot->loading(...$this->components); |
||
| 47 | |||
| 48 | $this->ready && yield $boot->app()->starting()->perform(); |
||
| 49 | |||
| 50 | logger('console')->info('Application prepared to run'); |
||
| 51 | |||
| 52 | return yield $this->firing($boot->app()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 53 | } |
||
| 54 | } |
||
| 55 |