Inheritance: extends Zend\Code\Generator\ValueGenerator
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('Writing application configuration...');
     // set config dir
     $configFile = $this->params->moduleConfigDir . '/module.config.php';
     // create src module
     if (!file_exists($configFile)) {
         $this->console->writeFailLine('task_update_config_module_config_not_exists', [$this->console->colorize($configFile, Color::GREEN)]);
         return false;
     }
     // get config data from file
     $configData = (include $configFile);
     // add controller config
     $configData = $this->addControllerConfig($configData);
     // add form config
     $configData = $this->addFormConfig($configData);
     // add routing config
     $configData = $this->addRoutingConfig($configData);
     // add translate config
     $configData = $this->addTranslateConfig($configData);
     // add navigation config
     $configData = $this->addNavigationConfig($configData);
     // create config array
     $config = new ConfigArrayGenerator($configData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write file
     file_put_contents($configFile, $file->generate());
     return 0;
 }
Example #2
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // check for project
     if ($this->params->paramWithProject) {
         // output message
         $this->console->writeTaskLine('task_generate_map_template_map_running');
         // define generator files
         if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
             $generator = $this->params->workingPath . '/vendor/bin/templatemap_generator.php.bat';
             $command = $generator . ' -l ' . $this->params->moduleDir . ' -v ' . $this->params->moduleDir . DIRECTORY_SEPARATOR . 'view';
         } else {
             $generator = $this->params->workingPath . '/vendor/bin/templatemap_generator.php';
             $command = 'php ' . $generator . ' -l ' . $this->params->moduleDir . ' -v ' . $this->params->moduleDir . DIRECTORY_SEPARATOR . 'view';
         }
         // create src module
         if (!file_exists($generator)) {
             $this->console->writeFailLine('task_generate_map_template_map_not_exists');
             return 1;
         }
         // run templatemap generator
         exec($command, $output, $return);
     } else {
         // create config array
         $config = new ConfigArrayGenerator(array(), $this->params);
         // create file
         $file = new ConfigFileGenerator($config->generate(), $this->params->config);
         // setup map file
         $mapFile = $this->params->moduleDir . DIRECTORY_SEPARATOR . 'template_map.php';
         // write file
         file_put_contents($mapFile, $file->generate());
     }
     return 0;
 }
 /**
  * Remove service manager config
  *
  * @param string $configType
  * @param string $configKey
  *
  * @return bool
  */
 public function removeConfig($configType, $configKey)
 {
     // set config dir
     $configFile = $this->params->moduleConfigDir . '/module.config.php';
     // create src module
     if (!file_exists($configFile)) {
         $this->console->writeFailLine('task_remove_config_module_config_file_not_exists', array($this->console->colorize($configFile, Color::GREEN)));
         return false;
     }
     // get config data from file
     $configData = (include $configFile);
     // delete factories key if set
     if (isset($configData[$configType]['factories']) && isset($configData[$configType]['factories'][$configKey])) {
         unset($configData[$configType]['factories'][$configKey]);
     }
     // delete invokables key if set
     if (isset($configData[$configType]['invokables']) && isset($configData[$configType]['invokables'][$configKey])) {
         unset($configData[$configType]['invokables'][$configKey]);
     }
     // create config array
     $config = new ConfigArrayGenerator($configData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write file
     file_put_contents($configFile, $file->generate());
     return true;
 }
Example #4
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_module_activate_module_config_file', array($this->console->colorize($this->params->configFile, Color::GREEN)));
     // set config dir and file
     $configFile = $this->params->projectConfigDir . '/' . $this->params->configFile;
     // create src module
     if (!file_exists($configFile)) {
         $this->console->writeFailLine('task_module_activate_module_config_file_not_exists', array($this->console->colorize($configFile, Color::GREEN)));
         return 1;
     }
     // get config data from file
     $configData = (include $configFile);
     // create src module
     if (!is_array($configData) || !isset($configData['modules'])) {
         $this->console->writeFailLine('task_module_activate_module_not_zf2_config_file', array($this->console->colorize($configFile, Color::GREEN)));
         $this->console->writeFailLine('task_module_activate_module_no_modules_array_section', array($this->console->colorize('modules', Color::GREEN)));
         return 1;
     }
     // add module to application configuration
     if (!in_array($this->params->paramModule, $configData['modules'])) {
         $configData['modules'][] = $this->params->paramModule;
     }
     // create config array
     $config = new ConfigArrayGenerator($configData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write class to file
     file_put_contents($configFile, $file->generate());
     return 0;
 }
Example #5
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // check for project
     if (!$this->params->paramWithProject) {
         return 0;
     }
     // check for activation
     if (!$this->params->paramDeactivation) {
         return 0;
     }
     // output message
     $this->console->writeTaskLine('task_module_deactivate_module_config_file', [$this->console->colorize($this->params->configFile, Color::GREEN)]);
     // check for chosen config file
     if ($this->params->configFile) {
         $configFiles = [$this->params->configFile];
     } else {
         // set filter dirs
         $filterDirs = ['..', '.', 'autoload'];
         // get existing config files
         $configFiles = array_values(array_diff(scandir($this->params->projectConfigDir), $filterDirs));
     }
     // remove dirs
     foreach ($configFiles as $key => $configFile) {
         if (is_dir($this->params->projectConfigDir . '/' . $configFile)) {
             unset($configFiles[$key]);
         }
     }
     $configFiles = array_values($configFiles);
     // loop through config files
     foreach ($configFiles as $configFile) {
         $configFile = $this->params->projectConfigDir . '/' . $configFile;
         // check for chosen config file
         if ($this->params->configFile && !file_exists($configFile)) {
             $this->console->writeFailLine('task_module_deactivate_module_config_file_not_exists', [$this->console->colorize($configFile, Color::GREEN)]);
             return 1;
         }
         // get config data from file
         $configData = (include $configFile);
         // check for chosen config file
         if ($this->params->configFile && !is_array($configData) || !isset($configData['modules'])) {
             $this->console->writeFailLine('task_module_deactivate_module_not_zf2_config_file', [$this->console->colorize($configFile, Color::GREEN)]);
             $this->console->writeFailLine('task_module_deactivate_module_no_modules_array_section', [$this->console->colorize('modules', Color::GREEN)]);
             return 1;
         }
         // remove module from application configuration
         if (isset($configData['modules']) && in_array($this->params->paramModule, $configData['modules'])) {
             $moduleKey = array_search($this->params->paramModule, $configData['modules']);
             unset($configData['modules'][$moduleKey]);
         }
         // create config array
         $config = new ConfigArrayGenerator($configData, $this->params);
         // create file
         $file = new ConfigFileGenerator($config->generate(), $this->params->config);
         // write class to file
         file_put_contents($configFile, $file->generate());
     }
     return 0;
 }
 /**
  * Update service manager config
  *
  * @param string $configType
  * @param string $configKey
  * @param string $configClass
  * @param string $namespaceName
  *
  * @return bool
  */
 public function updateConfig($configType, $configKey, $configClass, $namespaceName)
 {
     // set config dir
     $configFile = $this->params->moduleConfigDir . '/module.config.php';
     // create src module
     if (!file_exists($configFile)) {
         $this->console->writeFailLine('task_update_config_module_config_not_exists', [$this->console->colorize($configFile, Color::GREEN)]);
         return false;
     }
     // get config data from file
     $configData = (include $configFile);
     // check for config key
     if (!isset($configData[$configType])) {
         $configData[$configType] = [];
     }
     // remove factory if requested
     if ($this->params->paramRemoveFactory) {
         // delete factories key if set
         if (isset($configData[$configType]['factories']) && isset($configData[$configType]['factories'][$configKey])) {
             unset($configData[$configType]['factories'][$configKey]);
         }
     }
     // check for factory
     if ($this->params->paramFactory) {
         // check for factories config key
         if (!isset($configData[$configType]['factories'])) {
             $configData[$configType]['factories'] = [];
         }
         // set class and namespace
         $class = $this->params->paramModule . '\\' . $namespaceName . '\\' . $configClass . 'Factory';
         // add class
         $configData[$configType]['factories'][$configKey] = $class;
         // delete invokables key if set
         if (isset($configData[$configType]['invokables']) && isset($configData[$configType]['invokables'][$configKey])) {
             unset($configData[$configType]['invokables'][$configKey]);
         }
     } else {
         // check for invokables config key
         if (!isset($configData[$configType]['invokables'])) {
             $configData[$configType]['invokables'] = [];
         }
         // set class and namespace
         $class = $this->params->paramModule . '\\' . $namespaceName . '\\' . $configClass;
         // add class
         $configData[$configType]['invokables'][$configKey] = $class;
     }
     // create config array
     $config = new ConfigArrayGenerator($configData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write file
     file_put_contents($configFile, $file->generate());
     return true;
 }
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_module_generate_module_config_writing');
     // setup config data for view manager
     $configData = array('view_manager' => array('template_map' => 'include ' . $this->params->moduleRootConstant . ' . \'/template_map.php\',', 'template_path_stack' => 'array(' . $this->params->moduleRootConstant . ' . \'/view\')'));
     // create config array
     $config = new ConfigArrayGenerator($configData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write file
     file_put_contents($this->params->moduleConfigDir . '/module.config.php', $file->generate());
     return 0;
 }
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_module_update_view_manager_writing');
     // set config dir
     $configFile = $this->params->moduleConfigDir . '/module.config.php';
     // create src module
     if (!file_exists($configFile)) {
         $this->console->writeFailLine('task_module_update_view_manager_config_file_not_exists', [$this->console->colorize($configFile, Color::GREEN)]);
         return 1;
     }
     // get config data from file
     $configData = (include $configFile);
     // check for view_manager config key
     if (!isset($configData['view_manager'])) {
         $configData['view_manager'] = [];
     }
     // check for view_manager config key
     if (!isset($configData['view_manager']['template_path_stack'])) {
         $configData['view_manager']['template_path_stack'] = [];
     }
     // check for template path stack
     if (!in_array($this->params->moduleDir . '/view', $configData['view_manager']['template_path_stack'])) {
         // set template path
         $templatePath = $this->params->moduleRootConstant . ' . \'/view\'';
         // add template path to stack
         $configData['view_manager']['template_path_stack'][] = $templatePath;
     }
     // create config array
     $config = new ConfigArrayGenerator($configData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write file
     file_put_contents($configFile, $file->generate());
     return 0;
 }
Example #9
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_module_create_routing_writing');
     // set config dir
     $configFile = $this->params->moduleConfigDir . '/module.config.php';
     // create src module
     if (!file_exists($configFile)) {
         $this->console->writeFailLine('task_module_create_routing_config_file_not_exists', array($this->console->colorize($configFile, Color::GREEN)));
         return 1;
     }
     // get config data from file
     $configData = (include $configFile);
     // check if controller exists
     if (!isset($configData['controllers']) || count($configData['controllers']) == 0) {
         $this->console->writeFailLine('task_module_create_routing_controller_not_exists', array($this->console->colorize($this->params->paramModule, Color::GREEN)));
         return 1;
     }
     // set routing key
     $routingKey = strtolower($this->params->paramModule);
     // check for existing router config
     if (isset($configData['router'])) {
         // check for existing routes config
         if (isset($configData['router']['routes']) && isset($configData['router']['routes'][$routingKey])) {
             // output confirm prompt
             $deleteConfirmation = $this->console->writeConfirmPrompt('task_module_create_routing_prompt_1', 'task_module_create_routing_yes_answer', 'task_module_create_routing_no_answer');
             if (!$deleteConfirmation) {
                 // output success message
                 $this->console->writeOkLine('task_module_create_routing_not_overwritten', array($this->console->colorize($this->params->paramModule, Color::GREEN)));
                 return 1;
             }
         }
     } else {
         $configData['router'] = array('routes' => array());
     }
     // check for strict mode
     if ($this->params->paramStrict) {
         // create child routes
         $childRoutes = array();
         // loop through loaded controller actions
         foreach ($this->params->loadedActions[$this->params->paramModule] as $loadedController => $loadedActions) {
             $controllerName = $this->filterCamelCaseToDash(str_replace($this->params->paramModule . '\\', '', $loadedController));
             $actionList = array_keys($loadedActions);
             $childRoutes[$controllerName . '-action'] = array('type' => 'segment', 'options' => array('route' => '/' . $controllerName . '[/:action[/:id]]', 'defaults' => array('controller' => $controllerName), 'constraints' => array('action' => '(' . implode('|', $actionList) . ')', 'id' => '[0-9_-]*')));
         }
     } else {
         // create child routes
         $childRoutes = array('controller-action' => array('type' => 'segment', 'options' => array('route' => '/:controller[/:action[/:id]]', 'constraints' => array('controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9_-]*'))));
     }
     // set controller keys
     $controllerKeys = array();
     // merge controller keys
     foreach ($configData['controllers'] as $group) {
         $controllerKeys = array_merge($controllerKeys, array_keys($group));
     }
     // identify default controller
     if (count($controllerKeys) == 1) {
         $defaultController = reset($controllerKeys);
     } else {
         $indexController = $this->params->paramModule . '\\Index';
         $moduleController = $this->params->paramModule . '\\' . $this->params->paramModule;
         if (in_array($indexController, $controllerKeys)) {
             $defaultController = $indexController;
         } elseif (in_array($moduleController, $controllerKeys)) {
             $defaultController = $moduleController;
         } else {
             $defaultController = reset($controllerKeys);
         }
     }
     // clear leading namespace
     if (stripos($defaultController, $this->params->paramModule) === 0) {
         $defaultController = str_replace($this->params->paramModule . '\\', '', $defaultController);
     }
     // create route
     $configData['router']['routes'][$routingKey] = array('type' => 'Literal', 'options' => array('route' => '/' . $this->filterCamelCaseToDash($this->params->paramModule), 'defaults' => array('__NAMESPACE__' => $this->params->paramModule, 'controller' => $defaultController, 'action' => 'index')), 'may_terminate' => true, 'child_routes' => $childRoutes);
     // create config array
     $config = new ConfigArrayGenerator($configData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write file
     file_put_contents($configFile, $file->generate());
     return 0;
 }
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_crud_generate_translation_file_writing');
     // prepare identifier
     $entityName = str_replace('Entity', '', $this->params->paramEntityClass);
     $moduleIdentifier = $this->filterCamelCaseToUnderscore($this->params->paramModule);
     $entityIdentifier = $this->filterCamelCaseToUnderscore($entityName);
     /** @var ClassReflection $loadedEntity */
     $loadedEntity = $this->params->loadedEntity;
     // setup translation data
     $translationData = [$moduleIdentifier . '_title_index' => $entityName . ' overview', $moduleIdentifier . '_title_show' => $entityName . ' view', $moduleIdentifier . '_title_create' => $entityName . ' create', $moduleIdentifier . '_title_update' => $entityName . ' update', $moduleIdentifier . '_title_delete' => $entityName . ' delete', $moduleIdentifier . '_navigation_index' => $entityName, $moduleIdentifier . '_navigation_show' => $entityName . ' view', $moduleIdentifier . '_navigation_create' => $entityName . ' create', $moduleIdentifier . '_navigation_update' => $entityName . ' update', $moduleIdentifier . '_navigation_delete' => $entityName . ' delete', $moduleIdentifier . '_action_index' => $entityName . ' overview', $moduleIdentifier . '_action_show' => 'Show ' . $entityName, $moduleIdentifier . '_action_save' => 'Save ' . $entityName, $moduleIdentifier . '_action_create' => 'Create ' . $entityName, $moduleIdentifier . '_action_update' => 'Update ' . $entityName, $moduleIdentifier . '_action_delete' => 'Delete ' . $entityName];
     // loop through entity properties
     foreach ($loadedEntity->getProperties() as $property) {
         $key = $moduleIdentifier . '_label_' . $this->filterCamelCaseToUnderscore($property->getName());
         $text = ucfirst($property->getName());
         $translationData[$key] = $text;
     }
     $loadedTable = $this->params->loadedTables[$entityIdentifier];
     /** @var ConstraintObject $primaryKey */
     $primaryKey = $loadedTable['primaryKey'];
     $primaryColumns = $primaryKey->getColumns();
     /** @var ColumnObject $column */
     foreach ($loadedTable['columns'] as $column) {
         if ($column->getDataType() == 'enum') {
             foreach ($column->getErrata('permitted_values') as $value) {
                 $key = $column->getTableName() . '_option_' . $column->getName() . '_' . $value;
                 $text = $value;
                 $translationData[$key] = $text;
             }
         }
     }
     $key = $moduleIdentifier . '_message_' . $entityIdentifier . '_not_found';
     $text = 'No ' . $entityName . ' found.';
     $translationData[$key] = $text;
     $key = $moduleIdentifier . '_message_' . $entityIdentifier . '_data_invalid';
     $text = $entityName . ' data invalid. Please check your input.';
     $translationData[$key] = $text;
     $key = $moduleIdentifier . '_message_' . $entityIdentifier . '_saving_success';
     $text = $entityName . ' was saved.';
     $translationData[$key] = $text;
     $key = $moduleIdentifier . '_message_' . $entityIdentifier . '_saving_failed';
     $text = $entityName . ' could not be saved.';
     $translationData[$key] = $text;
     $key = $moduleIdentifier . '_message_' . $entityIdentifier . '_deleting_possible';
     $text = 'You can delete the ' . $entityName . ' now.';
     $translationData[$key] = $text;
     $key = $moduleIdentifier . '_message_' . $entityIdentifier . '_deleting_success';
     $text = $entityName . ' was deleted.';
     $translationData[$key] = $text;
     $key = $moduleIdentifier . '_message_' . $entityIdentifier . '_deleting_failed';
     $text = $entityName . ' could not be deleted.';
     $translationData[$key] = $text;
     /** @var ColumnObject $column */
     foreach ($loadedTable['columns'] as $column) {
         $columnText = str_replace('_', ' ', $column->getName());
         if ($column->getDataType() == 'enum') {
             $key = $column->getTableName() . '_message_' . $column->getTableName() . '_' . $column->getName() . '_inarray';
             $text = 'Invalid ' . $column->getTableName() . ' ' . $columnText . '!';
             $translationData[$key] = $text;
         } elseif ($column->getDataType() == 'varchar') {
             $key = $column->getTableName() . '_message_' . $column->getTableName() . '_' . $column->getName() . '_stringlength';
             $text = 'Wrong length for ' . $column->getTableName() . ' ' . $columnText . '!';
             $translationData[$key] = $text;
         } elseif ($column->getDataType() == 'char') {
             $key = $column->getTableName() . '_message_' . $column->getTableName() . '_' . $column->getName() . '_stringlength';
             $text = 'Wrong length for ' . $column->getTableName() . ' ' . $columnText . '!';
             $translationData[$key] = $text;
         }
         if (in_array($column->getName(), $primaryColumns)) {
             $required = 'false';
         } elseif ($column->isNullable() === false) {
             $required = 'true';
         } else {
             $required = 'false';
         }
         if ($required) {
             $key = $column->getTableName() . '_message_' . $column->getTableName() . '_' . $column->getName() . '_notempty';
             $text = ucfirst($columnText) . ' should not be empty!';
             $translationData[$key] = $text;
         }
     }
     // create config array
     $config = new ConfigArrayGenerator($translationData, $this->params);
     // create file
     $file = new ConfigFileGenerator($config->generate(), $this->params->config);
     // write file
     file_put_contents($this->params->applicationLanguageDir . '/en_US.php', $file->generate());
     return 0;
 }