예제 #1
0
 /**
  * Format migration - fills all data values
  *
  * @param string $file Migration file name
  * @param string $pathAlias Migratoin path yii-alias
  * @return array Formatted migration
  */
 protected function formatMigration($file, $pathAlias)
 {
     $path = Yii::getAlias($pathAlias) . DIRECTORY_SEPARATOR . $file;
     $pathInfo = pathinfo($path);
     $formattedMigration = ['path_alias' => $pathAlias];
     $name = str_replace('.' . $pathInfo['extension'], '', $pathInfo['basename']);
     $formattedMigration['name'] = $name;
     $formattedMigration['module'] = PathHelper::getModuleAlias($path, $this->migrationDir, $this->modulesDir);
     return $formattedMigration;
 }
예제 #2
0
 /**
  * Gather all i18n messages files
  *
  * @return array
  */
 public function loadI18n()
 {
     $i18nPaths = PathHelper::getTargetPaths($this->configPaths, $this->module, $this->modulesDir, $this->i18nDir, false);
     $i18nConfig = ['components' => ['i18n' => ['translations' => []]]];
     foreach ($i18nPaths as $i18nPath) {
         $realPath = Yii::getAlias($i18nPath);
         if (is_dir($realPath)) {
             $fileMap = [];
             $handle = opendir($realPath);
             $categoryPrefix = 'c';
             $categoryName = '';
             while (($dir = readdir($handle)) !== false) {
                 if ($dir === '.' || $dir === '..') {
                     continue;
                 }
                 if (is_dir($realPath . DIRECTORY_SEPARATOR . $dir)) {
                     if (!$categoryName) {
                         foreach ($this->configPaths as $configPath) {
                             if (strpos($realPath, substr($configPath, 1)) !== false) {
                                 $categoryPrefix = substr($configPath, 1, 1);
                                 break;
                             }
                         }
                         $categoryName = PathHelper::getModuleAlias($realPath . DIRECTORY_SEPARATOR . $dir, $this->i18nDir, $this->modulesDir);
                         $categoryName = $categoryPrefix . '/' . $categoryName;
                     }
                     $filesHandle = opendir($realPath . DIRECTORY_SEPARATOR . $dir);
                     while (($file = readdir($filesHandle)) !== false) {
                         if ($file === '.' || $file === '..') {
                             continue;
                         }
                         $categoryAlias = str_replace('.php', '', $file);
                         if ($categoryPrefix . '/' . $categoryAlias == $categoryName) {
                             $fileMap[$categoryName] = $file;
                         } else {
                             $fileMap[$categoryName . '/' . $categoryAlias] = $file;
                         }
                     }
                     closedir($filesHandle);
                 }
             }
             closedir($handle);
             $i18nConfig['components']['i18n']['translations'][$categoryName . '*'] = ['class' => $this->i18nClass, 'basePath' => $i18nPath, 'forceTranslation' => true, 'fileMap' => $fileMap];
         }
     }
     $this->config = ArrayHelper::merge($this->config, $i18nConfig);
 }