/**
  *
  * @param zool\file\File $resourceFile
  * @return File
  */
 private function copyToResources($resourceFile, $resourcePath)
 {
     $baseName = $resourceFile->getFileNameWithoutExtension();
     $extension = $resourceFile->getExtension();
     $fileHash = HashGenerator::instance()->hash($resourceFile->getMTime(), 7);
     $hashedBaseName = $baseName . '_' . $fileHash;
     $hashedResourcePath = str_replace($baseName, $hashedBaseName, $resourcePath);
     $targetPath = RESOURCES_PATH . '/' . $hashedResourcePath;
     $targetFile = new File($targetPath);
     if (!$targetFile->exists()) {
         /*
          * Delete previous versions of file
          */
         $targetDir = $targetFile->getDirectory();
         if ($targetDir->exists()) {
             $baseName = $targetFile->getFileNameWithoutExtension();
             $prevFilesPattern = '/^' . $baseName . '_(.){7}\\.' . $extension . '$/i';
             $prevoiusFiles = $targetDir->getFiles(false, $prevFilesPattern);
             foreach ($prevoiusFiles as $prevFilePath) {
                 (new File($prevFilePath))->delete();
             }
         }
         $targetFile->content($resourceFile->content());
     }
     return [$targetFile, RESOURCES_DIRNAME . '/' . $hashedResourcePath];
 }
 /**
  * @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;
     }
 }