/** * * @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]; }
/** * @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(); }
/** * * @param string $deploymentDescriptorPath absolute path of descriptor file * $return array module deployment descriptor */ public function deploy() { $compontens = []; $models = []; $modules = []; $moduleInfo = []; $moduleInfoFile = new File("{$this->modulePath}/" . ModuleInfo::MODULE_INFO_FILENAME); if ($moduleInfoFile->exists()) { $moduleInfo = $moduleInfoFile->includeFile(); } else { $this->log->console("Missing module info file in {$this->modulePath}", null, Log::WARNING); } $componentsDir = new Directory("{$this->modulePath}/" . self::COMPONENTS_FOLDER); if ($componentsDir->exists()) { $compontens = $componentsDir->getFiles(true, self::PHP_FILE_FILTER); } $modelsDir = new Directory("{$this->modulePath}/" . self::MODELS_FOLDER); if ($modelsDir->exists()) { $modelsTmp = $modelsDir->getFiles(true, self::PHP_FILE_FILTER); foreach ($modelsTmp as $modelPath) { $class = substr($modelPath, strrpos($this->modulePath, DS) + 1); // remove path $class = substr($class, 0, -4); // remove .php extendsion $class = str_replace(DS, '\\', $class); // direectory separator to namespace separator $models[$class] = $modelPath; } } $modulesDir = new Directory("{$this->modulePath}/" . self::MODULES_FOLDER); if ($modulesDir->exists()) { foreach ($modulesDir->getDirectories() as $subModulePath) { $moduleName = substr(str_replace($modulesDir->getPath(), '', $subModulePath), 1); $subModuleDeployer = new ModuleDeployer($subModulePath); $modules[$moduleName] = $subModuleDeployer->deploy(); } } return ['path' => $this->modulePath, 'compontents' => $compontens, 'modules' => $modules, 'models' => $models, 'info' => $moduleInfo]; }
/** * @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 scanApplications($app, $appPath) { $info = []; $moduleInfoFile = new File("{$appPath}/" . ModuleInfo::MODULE_INFO_FILENAME); if ($moduleInfoFile->exists()) { $info = $moduleInfoFile->includeFile(); } else { $this->log->console("Missing module info file in {$appPath}", null, Log::WARNING); } $this->addModule($app, ['path' => $appPath, 'info' => $info]); }
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()); } }