loadCommandsControllers($this->getCommands()); parent::run($input, $output); } /** * Get all available files * @return array */ protected function getCommands() { $files = glob(ModuleConstants::getFullPath('app', $this->dir) .DIRECTORY_SEPARATOR. '*.php'); $commands = []; foreach ($files as $file) { $file = substr($file, strrpos($file, DIRECTORY_SEPARATOR) + 1); $file = substr($file, 0, strrpos($file, '.')); $commands[] = $file; } return $commands; } /** * Create new objects and add it * @param $commands */ protected function loadCommandsControllers($commands) { $this->dir = str_replace('/', DIRECTORY_SEPARATOR, $this->dir); foreach ($commands as $command) { $class = ModuleConstants::getRootNamespace() . '\App\\' . $this->dir . '\\' . $command; $this->add(new $class); } } }