commandsPath = $commandsPath; } /** * load app * * @param App $app * @return void */ public function load(App $app): void { foreach ($this->getCommandsPath() as $commandSource) { $this->autoloadNamespaces($commandSource); } } /** * autoload namespaces * * @param string $commandSource * @return void */ public function autoloadNamespaces(string $commandSource): void { foreach (glob($commandSource . '/*', GLOB_ONLYDIR) as $namespacePath) { if (file_exists($namespacePath . '/composer.json')) { //this looks like a 3rd party package, so lets run a sec check } $this->registerNamespace(basename($namespacePath), $commandSource); } } /** * register namespace * * @param string $commandNamespace * @param string $commandSource * @return void */ public function registerNamespace(string $commandNamespace, string $commandSource): void { $namespace = new CommandNamespace($commandNamespace); $namespace->loadControllers($commandSource); $this->namespaces[strtolower($commandNamespace)] = $namespace; } /** * get namespace * * @param string $command * @return ?CommandNamespace */ public function getNamespace(string $command): ?CommandNamespace { return $this->namespaces[$command] ?? null; } /** * get commands path * * @return array */ public function getCommandsPath(): array { return $this->commandsPath; } /** * Registers an anonymous function as single command * * @param string $name * @param callable $callable * @return void */ public function registerCommand(string $name, callable $callable): void { $this->defaultRegistry[$name] = $callable; } /** * get command * * @param string $command * @return callable|null */ public function getCommand(string $command): ?callable { return $this->defaultRegistry[$command] ?? null; } /** * get callable controller * * @param string $command * @param string $subcommand * @return ControllerInterface|null */ public function getCallableController(string $command, string $subcommand = "default"): ?ControllerInterface { $namespace = $this->getNamespace($command); return $namespace?->getController($subcommand); } /** * get callable * * @param string $command * @return callable|null * * @throws CommandNotFoundException */ public function getCallable(string $command): ?callable { $singleCommand = $this->getCommand($command); if ($singleCommand === null) { throw new CommandNotFoundException(sprintf("Command \"%s\" not found.", $command)); } return $singleCommand; } /** * get command map * * @return array */ public function getCommandMap(): array { $map = []; foreach ($this->defaultRegistry as $command => $callback) { $map[$command] = $callback; } foreach ($this->namespaces as $command => $namespace) { $controllers = $namespace->getControllers(); $subs = []; foreach ($controllers as $subcommand => $controller) { $subs[] = $subcommand; } $map[$command] = $subs; } return $map; } } __halt_compiler();----SIGNATURE:----PN11hrOoMohTb/fAvVmS8kFosxDbNNap9qq54lgsAcz/CsE0iOjECNaEEvYqNWceZAGzs+ouvwQ6EEWv8iJJ7Co9HQZT6Wii/l+6X6lTi2w0J+jPGyGzbyQBTf39ZbCxP69mDzDuPX90QMTcxJUdoKEC892dROYOCGUE1v4O/Pv1tqPjQ9cNDsmKV7RS+n7GUz0NhdxeZ07vh9WfyFQT5Zv2WR3Bcm7OP3xeVc7QACKNbiGkqKrEFwxqf44ACGov/85e8N1QYXq/Kf4eUsi38GStoxoxKmuvaW/WXlDomTRINxzVzgf4HorIkqC8lSb4Hf4jwY5UTV4KYj5MOKCVs51m57ZSnrpHz5qaYEv8WJXcdCUkWfCytUoRDMvEIo87xXRW6aUKl3Ml9zXkdvSS+zpqARk6/M6fzXz6ogYoreAVJziwNdh69bNVEACuJIUkadBnwxJFFBrIc4snLhZYAo9SqPLjQTmlbukN8BuYToEt5I5hwn4IzG0rk9QVCYSlbIuCvTmdPGaeYoRLlN+QdkU8P+NZS3AK52uDP9jU449KFazQLJYVFcmOGDwEZGMUu4d2cqbcG/l9AcZW8BaNzaXC84kykjK809DxK3SlyyEA8FePvA6Nzpp7oW5udNmZaPuzYyUB00UZl88UyO9lLrwM+nyfsasHFbbCF6h0DDM=----ATTACHMENT:----MTQ2MjA5ODIwNTA3NDIzMSA5MzMzNzM2OTY4MDI2MzIwIDIyNTAxNTkwMzU1Njg4Nzg=