Beispiel #1
0
 /**
  * bind text domain for all enabled modules.
  * it is better to not load all modules at once. (recommend not to call this method).
  * 
  * @param string $language_locale_uri language locale uri.
  */
 public function bindTextDomainForModules($language_locale_uri)
 {
     $Language = $this->Silexapp['Language'];
     $modules_list = $this->getAllAvailableModules();
     if (is_array($modules_list) && array_key_exists('items', $modules_list) && is_array($modules_list['items'])) {
         $Metadata = new \System\Libraries\Modules\Metadata();
         foreach ($modules_list['items'] as $row) {
             $module_metadata = $Metadata->readModuleMetadata($row->module_system_name);
             if (is_array($module_metadata) && isset($module_metadata['Domain Path']) && isset($module_metadata['Text Domain'])) {
                 if (strpos($module_metadata['Text Domain'], ',') !== false) {
                     // text domain can have multiple per module. use comma (,) to separate them.
                     $text_domain_exp = explode(',', str_replace(', ', ',', $module_metadata['Text Domain']));
                     foreach ($text_domain_exp as $text_domain) {
                         $Language->bindTextDomain($text_domain, MODULE_PATH . DS . $row->module_system_name . DS . trim($module_metadata['Domain Path'], '/') . DS, $language_locale_uri);
                     }
                     unset($text_domain, $text_domain_exp);
                 } else {
                     $Language->bindTextDomain($module_metadata['Text Domain'], MODULE_PATH . DS . $row->module_system_name . DS . trim($module_metadata['Domain Path'], '/') . DS, $language_locale_uri);
                 }
             }
         }
         // endforeach;
         unset($Metadata, $module_metadata, $row);
     }
     unset($Language, $modules_list);
 }
Beispiel #2
0
 /**
  * execute command
  * 
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $names = $input->getOption('names');
     $site_ids = $input->getOption('siteIds');
     if ($names == null) {
         $output->writeln('<error>Sorry, you did not enter module folder name.</error>');
         unset($names, $site_ids);
         return false;
     }
     if ($names != null) {
         $names_exp = explode(',', str_replace(', ', ',', $names));
         // site_ids is optional so it have to check first.
         if ($site_ids != null) {
             $site_ids_exp = explode(',', str_replace(', ', ',', $site_ids));
         } else {
             $site_ids_exp = [];
         }
         $style = new \Symfony\Component\Console\Formatter\OutputFormatterStyle('white', 'green');
         $output->getFormatter()->setStyle('success', $style);
         unset($style);
         if (is_array($names_exp) && !empty($names_exp)) {
             foreach ($names_exp as $name) {
                 if ($name != null) {
                     $output->write('Module "' . $name . '": ');
                     if (is_dir(MODULE_PATH . DS . $name)) {
                         if (is_file(MODULE_PATH . DS . $name . DS . $name . '.php')) {
                             $Metadata = new \System\Libraries\Modules\Metadata();
                             $module_metadata = $Metadata->readModuleMetadata($name);
                             if (is_array($module_metadata) && array_key_exists('Version', $module_metadata) && $module_metadata['Version'] != null) {
                                 if (is_array($site_ids_exp) && !empty($site_ids_exp)) {
                                     $result = $this->prepareAddModuleSites($output, $name, $module_metadata, $site_ids_exp);
                                 } else {
                                     $result = $this->prepareAddModuleSites($output, $name, $module_metadata);
                                 }
                                 if (isset($result) && (empty($site_ids_exp) && $result > '0' || !empty($site_ids_exp) && count($site_ids_exp) == $result)) {
                                     $output->writeln('<success>added successfully.</success>');
                                 } elseif (!empty($site_ids_exp) && isset($result) && $result > '0' && $result < count($site_ids_exp)) {
                                     $output->writeln('<info>added some sites, make sure that all site id are really exists.</info>');
                                 } else {
                                     $output->writeln('<error>could not add, site id does not exists.</error>');
                                 }
                             } else {
                                 $output->writeln('<error>could not add, there is no metadata in metadata file.</error>');
                             }
                             unset($Metadata, $module_metadata);
                         } else {
                             $output->writeln('<error>could not add, module metadata file not found.</error>');
                         }
                     } else {
                         $output->writeln('<error>could not add, module folder is not exists.</error>');
                     }
                 }
                 // endif $name not null.
             }
             // endforeach;
         }
         // endif is array $name_exp
     }
     // also clear cache about this thing. ---------------------------
     $Command = $this->getApplication()->find('System\\Core\\Console\\Cache');
     $arguments = ['command' => 'System\\Core\\Console\\Cache', '--subfolder' => 'system/Libraries/Modules.php'];
     $CmdInput = new \Symfony\Component\Console\Input\ArrayInput($arguments);
     $Command->run($CmdInput, new \Symfony\Component\Console\Output\NullOutput());
     unset($arguments, $CmdInput, $Command);
     // end clear cache ------------------------------------------------
     unset($name, $names, $names_exp, $result, $site_ids, $site_ids_exp);
 }