baseCommandsPath === null) { $this->baseCommandsPath = implode(DIRECTORY_SEPARATOR, [ dirname(__DIR__, 1), 'Command' ]); } $this->baseCommandsPath = realpath($this->baseCommandsPath); } public function getCommandsList(): array { $commands = []; $files = new RecursiveIteratorIterator((new RecursiveDirectoryIterator($this->baseCommandsPath))); foreach ($files as $file) { if ($file->isDir()) { continue; } $basename = ltrim(str_replace(DIRECTORY_SEPARATOR, "\\", str_replace([$this->baseCommandsPath, '.php'], '', $file->getRealPath())), "\\"); $namespace = "Incoviba\\Command"; $class = "{$namespace}\\{$basename}"; if (!class_exists($class)) { $this->logger->error("Class {$class} not found"); continue; } $ref = new ReflectionClass($class); $commandData = $ref->getAttributes(AsCommand::class)[0]; $commandName = $commandData->getArguments()['name']; if (in_array($commandName, $this->skipCommands) or in_array($class, $this->skipCommands)) { continue; } $commands[$commandName] = $class; } return $commands; } }