/** * Returns available commands of a specified module. * @param \yii\base\Module $module the module instance * @return array the available command names */ protected function getModuleCommands($module) { $prefix = $module instanceof Application ? '' : $module->getUniqueID() . '/'; $commands = []; foreach (array_keys($module->controllerMap) as $id) { $commands[] = $prefix . $id; } foreach ($module->getModules() as $id => $child) { if (($child = $module->getModule($id)) === null) { continue; } foreach ($this->getModuleCommands($child) as $command) { $commands[] = $command; } } $controllerPath = $module->getControllerPath(); if (is_dir($controllerPath)) { $files = scandir($controllerPath); foreach ($files as $file) { if (strcmp(substr($file, -14), 'Controller.php') === 0) { $commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14)); } } } return $commands; }