> */ private array $_process = []; /** */ public function init() { $this->import(ServerProviders::class); } /** * @throws */ public function withDatabase() { $this->import(DatabasesProviders::class); } /** * @throws */ public function withCrontab() { $this->import(CrontabProviders::class); } /** * @param string $class * @param Process $process */ public function addProcess(string $class, Process $process) { } /** * @return Process[] */ public function getProcess(): array { return $this->_process; } /** * @param string $class * @return Process|null */ public function getProcessName(string $class): ?Process { return $this->_process[$class] ?? null; } /** * @param Closure|array $closure * @return $this * @throws Exception */ public function middleware(Closure|array $closure): static { return $this; } /** * @param bool $useTree * @return $this * @throws Exception */ public function setUseTree(bool $useTree): static { return $this; } /** * @param string $service * @return $this * @throws */ public function import(string $service): static { if (!class_exists($service)) { return $this; } $class = Kiri::getDi()->get($service); if (method_exists($class, 'onImport')) { $class->onImport($this); } return $this; } /** * @param Kernel $kernel * @return $this */ public function commands(Kernel $kernel): static { foreach ($kernel->getCommands() as $command) { $this->register($command); } return $this; } /** * @param string $command * @throws */ public function register(string $command) { di(ConsoleApplication::class)->add(di($command)); } /** * @param array $argv * @return void */ public function execute(array $argv): void { ini_set('swoole.enable_preemptive_scheduler', 'On'); ini_set('swoole.enable_library', 'On'); [$input, $output] = $this->argument($argv); try { $console = di(ConsoleApplication::class); $command = $input->getFirstArgument(); if (empty($command)) { $command = 'sw:server'; } $command = $console->find($command); if ($command instanceof Command) { $this->enableFileChange($command, $input, $output); } } catch (\Throwable $exception) { $output->writeln(jTraceEx($exception)); } finally { Timer::clearAll(); } } /** * @param $argv * @return array */ private function argument($argv): array { return [new ArgvInput($argv), new ConsoleOutput()]; } /** * @param Command $class * @param $input * @param $output * @return void * @throws ReflectionException * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws Exception */ private function enableFileChange(Command $class, $input, $output): void { fire(new OnBeforeCommandExecute()); $this->container->setBindings(OutputInterface::class, $output); if (!($class instanceof Kiri\Server\ServerCommand)) { scan_directory(MODEL_PATH,'app\Model'); } $class->run($input, $output); fire(new OnAfterCommandExecute()); $output->writeln('ok' . PHP_EOL); } /** * @param $className * @param null $abstracts * @return stdClass * @throws Exception */ public function make($className, $abstracts = null): stdClass { return make($className, $abstracts); } }