__DIR__ . '/../app/Command', 'theme' => '', 'debug' => true, ], $config); $this->addService('config', new Config($config)); $commandsPath = $this->config->app_path; if (!is_array($commandsPath)) { $commandsPath = [ $commandsPath ]; } $commandSources = []; foreach ($commandsPath as $path) { if (str_starts_with($path, '@')) { $path = str_replace('@', $this->getAppRoot() . '/vendor/', $path) . '/Command'; } $commandSources[] = $path; } $this->addService('commandRegistry', new CommandRegistry($commandSources)); $this->setSignature($signature); $this->setTheme($this->config->theme); } /** * @return string */ public function getAppRoot(): string { $root_app = dirname(__DIR__); if (!is_file($root_app . '/vendor/autoload.php')) { $root_app = dirname(__DIR__, 4); } return $root_app; } /** * Magic method implements lazy loading for services * * @param string $name * @return mixed */ public function __get(string $name): mixed { if (!array_key_exists($name, $this->services)) { return null; } if (!array_key_exists($name, $this->loadedServices)) { $this->loadService($name); } return $this->services[$name]; } /** * add app service * * @param string $name * @param ServiceInterface $service * @return void */ public function addService(string $name, ServiceInterface|Closure $service): void { $this->services[$name] = $service; } /** * load app service * * @param string $name * @return void */ public function loadService(string $name): void { $service = $this->services[$name]; if ($service instanceof Closure) { $this->services[$name] = $service($this); $this->loadedServices[$name] = true; return; } $this->loadedServices[$name] = $service->load($this); } /** * Shortcut for accessing the Output Handler * * @return OutputHandler */ public function getPrinter(): OutputHandler { return $this->printer; } /** * Shortcut for setting the Output Handler * * @param OutputHandler $outputPrinter * @return void */ public function setOutputHandler(OutputHandler $outputPrinter): void { $this->services['printer'] = $outputPrinter; } /** * get app signature * * @return string */ public function getSignature(): string { return $this->appSignature; } /** * print signature * * @return void */ public function printSignature(): void { $this->getPrinter()->display($this->getSignature()); } /** * set signature * * @param string $appSignature * @return void */ public function setSignature(string $appSignature): void { $this->appSignature = $appSignature; } /** * Set the Output Handler based on the App's theme config setting * * @param string $loadedServices * @return void */ public function setTheme(string $loadedServices): void { $output = new OutputHandler(); $output->registerFilter( (new ThemeHelper($loadedServices)) ->getOutputFilter() ); $this->addService('printer', $output); } /** * register app command * * @param string $name * @param callable $callable * @return void */ public function registerCommand(string $name, callable $callable): void { $this->commandRegistry->registerCommand($name, $callable); } /** * run command * * @param array $argv * @return void * * @throws CommandNotFoundException */ public function runCommand(array $argv = []): void { $input = new CommandCall($argv); if (count($input->args) < 2) { $this->printSignature(); return; } $controller = $this->commandRegistry->getCallableController($input->command, $input->subcommand); if ($controller instanceof ControllerInterface) { $controller->boot($this); $controller->run($input); $controller->teardown(); return; } $this->runSingle($input); } /** * run single * * @param CommandCall $input * @throws CommandNotFoundException * * @return bool */ protected function runSingle(CommandCall $input): bool { try { $callable = $this->commandRegistry->getCallable($input->command); } catch (\Exception $e) { if (!$this->config->debug) { $this->getPrinter()->error($e->getMessage()); return false; } throw $e; } if (is_callable($callable)) { call_user_func($callable, $input); return true; } if (!$this->config->debug) { $this->getPrinter()->error("The registered command is not a callable function."); return false; } throw new CommandNotFoundException("The registered command is not a callable function."); } } __halt_compiler();----SIGNATURE:----fgW2vVhx+8cdfEMI0f6uHtT62Or7cGzb0TpEUTUbz3VoxVjMFkVVDhJ2BH0TDa/TUTKmTBvZ8qE5Se1VelMRBQo/UxqT9YLS+fLS/QDc7IXXi3IvYSkKgmi08cPg5TgtkGUmh5OJdRkZaflUGcpB+E23qhdbVCN/Ojt36ZsPFnxbkreNSR6L6u9Gw4ElcxtAi0uV+Tp314GkmAAa9boZl12Z+l7tSKGZMsyYB97ROtVJBaFzZSVd86BKJ27CPYpc2fVqMtS6lvS9h+Ke1aWm85gvYi9Pmz+2TaaCVMQO+btNtNMi3HUnZojrDMF3fTuiH4sENfIXAmiAPGHqIaIXUTusT0TNmf/236MVqMDvT9m6V/6O69Yg6WT9Kt7mafTyhSQdg8EHzJfK5HZlKnVW3TIZAvnJsrLhoPXleIhkilkaWxVMVT9AfMh1svdcsDGSMT+6VQ+ILCrcefMLY5Se5FP7Xoz7ALG6wUIFNukRUDMEQXCA8S7IKDZfP6wgbDXG1LCteobwmFepghuxMl+GrdSkyI267/D55vxV/zjYuWJKMHghYGHlzJpLKxCnfViHUoOxV7zX35PT2B44ULXRqGopCSzUKY4uIrqnSZq9/ivY5huF8MKR+AYcihU+QjvDQXZOA4I01012izwAmYaoXCoeAreMjPCAdD3BaIsBHMg=----ATTACHMENT:----NzM5OTYxNzEwODQwMTQ2MCA0MzMzOTE2ODI3NjM5MDIgNjIyNTc2ODA0NDAwNzkyNw==