/**
  * @param $alias cannot start with path separator. The module file alias looks like: module.path/file.php.<br/>
  * So the pattern is like: {module name}.{path in module}
  */
 public function resolve($alias)
 {
     list($moduleName, $path) = $this->moduleNameAndPath($alias);
     $modulePath = Modules::instance()->pathOf($moduleName);
     $resourceFile = new File($modulePath . '/' . $path);
     if (!$resourceFile->exists()) {
         throw new FileNotFoundException($resourceFile->getPath());
     }
     return $resourceFile->getPath();
 }
 /**
  * @see PathResolver
  * @param string $file file alias
  * @throws ZException when file not found
  * @return Ambigous <multitype:, multitype:NULL string , multitype:unknown string >
  */
 public function fromFileToTree($alias)
 {
     $filePath = PathResolver::instance()->resolve($alias);
     $file = new File($filePath);
     if (!$file->exists()) {
         throw new XmlException("Cannot open file {$file}.");
     }
     $tmpFilePath = $this->getTmpFilePath($alias, $file);
     $tmpFile = new File($tmpFilePath);
     /*
      * Catching
      */
     if ($tmpFile->exists()) {
         return require $tmpFile->getPath();
     } else {
         /*
          *  Remove old file
          */
         $targetDir = $tmpFile->getDirectory();
         if ($targetDir->exists()) {
             $baseName = $file->getFileNameWithoutExtension();
             $extension = $file->getExtension();
             $prevFilesPattern = '/^' . $baseName . '_(.){7}\\.' . $extension . '$/i';
             $prevoiusFiles = $targetDir->getFiles(false, $prevFilesPattern);
             foreach ($prevoiusFiles as $prevFilePath) {
                 (new File($prevFilePath))->delete();
             }
         }
         $doc = self::toTree($file->content());
         /*
          * Generates an interpretable code.
          */
         $exported = '<?php return ' . var_export($doc, true) . ";\n";
         $tmpFile->content($exported);
         return $doc;
     }
 }
 private function tryToLoadLocaleFormModule($lang, $module, $path, $fileBase)
 {
     if (in_array($module . self::MESSAGE_PATH_SEPARATOR . $fileBase, $this->loadedFileBases)) {
         return;
     }
     // set to flag do not load again
     $this->loadedFileBases[] = $module . self::MESSAGE_PATH_SEPARATOR . $fileBase;
     $localSuffix = '/' . self::LOCALE_DIRNAME . '/' . $lang . '/' . $fileBase . self::LOCALE_FILE_EXTENSION;
     $localeFile = new File($path . $localSuffix);
     if ($localeFile->exists()) {
         $this->messsages[$lang][$module . self::MESSAGE_PATH_SEPARATOR . $fileBase] = (require_once $localeFile->getPath());
     }
 }