__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:----PthOb2osAupk3RpXepmPvEXz+h505dbiDX/gdWVncKkj0MracIT76JrWzUwiawPPHl+vJ2MHq1srSiVWw8+OblKHIhdPpbXkSCKgEAqqif5jDoB2bt/Ol9K68gZWdfkfYaAHf7qaqH6TX98mWwiAJCVBT2HNDBybvQbEhPcG0vwSzUOTX5dZwuQ1tYjyv35buBhgL91uOnxFU4LODHq5yE4X8nlp5yLVNaRer0Tkn0PpPhtzr5CEaZ5+sY+fhsJdCTIBwbd78+cFnA4VIYt+UlPW3KyEbCm1gBAMxINt8lfqomcJ57d5cAPAL2ho6OtaDvY/nNMJs7u1Cgdy+f2yPjKJJPvD63HsmauiDOXAmFCcVO8L6/ZbvAjH7c68auEYwAHEahQwutHN1I6ZHQlERRwjQluX6MbRJwp6ZJ1yUEcESWMo9VtVMCCwbv1XQx7A/Pm9Bh1V5UKnTLPUsb+ni0IbSlvxAaMd6GKw5GsXcfZiLHG/DhePMZzlR674Fop1gXSxoZlOWul3Q35YDIyLkpWcxFlsqXauGzEPsGucBaM6SDi42MNPBEid6jSTpEUKqm5v0tItFKD1yz4IIU33EVOn5gUaA2sXRvW/uKFu+zaFWFlUnmWylK94CXSxXU9TmZObqqzTLVQ+fzXQYVoER8xoNQ1NcCmsMO0gMcxhYTM=----ATTACHMENT:----OTA0OTQzNTEwMTMyODI0OSA2NzY3NTc1ODUxODg5OTE2IDc0MjY5ODg5NjE1MzUwNDc=