errorHandler->registerShutdownHandler(\config('error.shutdown', [])); $this->errorHandler->registerExceptionHandler(\config('error.exception', [])); $this->errorHandler->registerErrorHandler(\config('error.error', [])); $this->id = \config('id', uniqid('id.')); $this->provider->on(OnBeforeCommandExecute::class, [$this, 'beforeCommandExecute']); } /** * @param OnBeforeCommandExecute $beforeCommandExecute * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws ReflectionException */ public function beforeCommandExecute(OnBeforeCommandExecute $beforeCommandExecute): void { if (!($beforeCommandExecute->command instanceof ServerCommand)) { $scanner = $this->container->get(Scanner::class); $scanner->read(APP_PATH . 'app/'); } else if (\config('reload.hot', false) === false) { $scanner = $this->container->get(Scanner::class); $scanner->read(APP_PATH . 'app/'); } } /** * @param string ...$services * @return $this * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function import(string ...$services): static { foreach ($services as $service) { if (!class_exists($service)) { continue; } /** @var Kiri\Abstracts\Provider $class */ $class = $this->container->get($service); if (method_exists($class, 'onImport')) { $class->onImport(); } } return $this; } /** * @param Kernel $kernel * @return $this * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function commands(Kernel $kernel): static { foreach ($kernel->getCommands() as $command) { $this->command($command); } return $this; } /** * @param string ...$command * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function command(string ...$command): void { $console = $this->container->get(ConsoleApplication::class); foreach ($command as $value) { $console->add($this->container->get($value)); } } /** * @param array $argv * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws ReflectionException * @throws Exception|ExceptionInterface */ public function execute(array $argv): void { /** @var ArgvInput $input */ $input = $this->container->bind(ArgvInput::class, new ArgvInput($argv)); /** @var ConsoleOutput $output */ $output = $this->container->bind(OutputInterface::class, new ConsoleOutput()); $console = $this->container->get(ConsoleApplication::class); $command = $console->find($input->getFirstArgument() ?? 'list'); fire(new OnBeforeCommandExecute($command)); $command->run($input, $output); fire(new OnAfterCommandExecute($command)); $output->writeln('execute complete.'); } }