errorHandler->registerShutdownHandler(\config('error.shutdown', [])); $this->errorHandler->registerExceptionHandler(\config('error.exception', [])); $this->errorHandler->registerErrorHandler(\config('error.error', [])); $this->id = \config('id', uniqid('id.')); $event = $this->container->get(Kiri\Events\EventProvider::class); $event->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 Kiri\Server\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 $service * @return $this * @throws */ public function import(string $service): static { if (!class_exists($service)) { return $this; } $class = $this->container->get($service); if (method_exists($class, 'onImport')) { $class->onImport($this->localService); } return $this; } /** * @param Kernel $kernel * @return $this * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws ReflectionException */ 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 * @throws ReflectionException */ public function command(string $command): void { $console = $this->container->get(ConsoleApplication::class); $console->add($this->container->get($command)); } /** * @param array $argv * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws ReflectionException * @throws Exception */ public function execute(array $argv): void { $input = new ArgvInput($argv); $this->container->bind(ArgvInput::class, $input); $output = new ConsoleOutput(); $this->container->bind(OutputInterface::class, $output); $console = $this->container->get(ConsoleApplication::class); $command = $console->find($input->getFirstArgument()); fire(new OnBeforeCommandExecute($command)); $command->run($input, $output); fire(new OnAfterCommandExecute($command)); $output->writeln('execute complete.' . PHP_EOL); } }