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:----ODq3GCOCzLlCWnmAsKR+4iQG/kBih5C1VPdj5T3JH2cM9dBi3dST1cb3HHhoVUC6aeRqF8YTFQ0NrImZPXZ9bXytkzyGyewf9AbprMOys3AOX8v8WQK3MLjpue6+xhjR388sTAszzYAY0IoaLUaUYsOZgpCZdRzc/CAMW6QWgN0UvoB7/ixWa+7qeYFsuiXG0jsdbgyLH6N1f3yzAtErqtGmDjxX/f0h4SUcUa0c0eVFnv7vbaGMXTLS11ZXERrpMmG/0TINhZ8x4zIlVjYt5QebXNVoxT95KCuA3uSuw8pU44vM+91qxRSFu0ATWIUZ3ixXYBoNdUQg+/l0BwMMGxEMsYGTHWqcJdauscpeNCilOhsr3GGNi5lk3UdwTObMTomYjEaLPNmU6RvIZhvmdlWon9RTs2m4MjS9OJrfv/xR7Qv6wARrvMDAhooV0GfT6j+ipPRvoIaMukLLnmZU9WkHiaYexUb1RSsXR6SvNU0n8C7q41cSxi1/2JDuRk04CbhoV43oLOoYz2W+J0GaDT6rf4XohZ75SjK9CC7mwQ9QJoIl+m1qAYu8nU0MHoH1b1LQM5Km94JWu2s5e9QwPkCmhsjrYe4/MFZjb/qzrbdhQC/ELPQk3lRt9tk/4UkXQRvvskY3B4xqTZNTpbVLn6JhPZ5L8eP8cu0IJ3JaYD0=----ATTACHMENT:----ODAzNDQ1MTY1MDY1MzIxMiA5NjA4MjA5NjEyMDcxNjQ1IDU4MDU4NzU5MjA1OTU4NjQ=