/** * CRUD for project modules */ public static function configureModules(Project &$project, LogInterface &$log) { $projectConfig = $project->getConfig(); do { Cmd::clear(); $log->debug('[ Project modules ]'); $log->repeat('-', '80', 'light_purple'); $options = array('N' => 'New Module'); $hasModules = $projectConfig->hasModules(); if ($hasModules) { self::listModules($projectConfig, $log); $options['C'] = 'Copy module'; $options['E'] = 'Edit modules'; $options['L'] = 'List modules'; } $options['B'] = 'Back'; $opt = Cmd::selectWithKeys($options, '>', $log); switch (strtolower($opt)) { case 'n': $moduleConfig = new ModuleConfig(); $moduleConfig->setProject($project); $module = Module::cliConfig($moduleConfig, $log); if ($module) { $config->addModule($module); } break; case 'e': if ($hasModules) { self::editModules($projectConfig, $log); } break; case 'c': $module = self::copyModule($config, $log); if ($module) { $config->addModule($copy); } break; case 'l': if ($hasModules) { self::listModules($config, $log); Cmd::readInput('Press enter to continue ...'); } break; case 'd': if ($hasModules) { self::deleteModules($config, $log); } break; case 'b': break 2; break; } } while (TRUE); }
/** * Configures a Module configuration object. * * @params \apf\core\project\module\Config $config a module configuration to be edited (optional). * @params \apf\iface\Log $log a log object to display configuration messages. * @return \apf\core\project\Module returns a configurated module. * @return boolean FALSE if the user aborts the configuration process. */ public static function configure(&$config = NULL, LogInterface &$log) { $isNew = $config === NULL; $config = new ModuleConfig($config); $project = $config->getProject(); if (!$project) { throw new \LogicException("Given module configuration has no assigned project"); } if (!$project->getConfig()) { throw new \LogicException("Passed project has not been properly configured"); } $projectConfig = $project->getConfig(); $module = new Module($config, $validate = 'none'); do { Cmd::clear(); $log->logArray(array("Project {$projectConfig->getName()}", "modules", $isNew ? 'create' : 'edit', $isNew ? '' : " > {$config->getName()}"), ' > ', 'light_purple'); $log->repeat('-', 80, 'light_purple'); $hasSubs = $config->hasSubs(); $options = array('N' => array('value' => sprintf('%s module name (%s)', $config->getName() ? 'Change' : 'Set', $config->getName()), 'color' => $config->getName() ? 'light_purple' : 'light_cyan'), 'D' => "Configure module directories", 'S' => "Configure subs"); if ($hasSubs) { $options['LS'] = 'List subs'; } $options['B'] = 'Back'; $opt = Cmd::selectWithKeys($options, '>', $log); switch (strtolower($opt)) { case 'n': self::configureName($config, $log); break; case 'd': if (!$config->getName()) { throw new \LogicException("You must configure the module name before configuring directories"); } $directoriesConfig = $config->getDirectories() ? $config->getDirectories()->getConfig() : new DirectoriesConfig($noConfig = NULL); $directoriesConfig->setModule($module); $directoriesConfig = Directories::cliConfig($directoriesConfig, $log); if ($directoriesConfig) { $config->setDirectories($directoriesConfig); } break; case 's': self::configureSubs($config, $log); break; case 'b': break 2; break; } } while (TRUE); return new Module($config, $validate = 'soft'); }