public function IndexAction() { $uri = $this->getRequest()->getUriNormal(); $template = $this->getRequest()->getUriPartByNum(-2); $fileDir = FileSystem::getDirName($uri, 2); $fileName = basename($uri); $filePath = $fileDir . "/" . $fileName; $imagesDir = $this->getConfig(["ImageProcessor", "directory"], "data/images"); $imagesDir = ROOT_DIR . "/" . $imagesDir; $realPath = ROOT_DIR . $filePath; $path = FileSystem::inDir($imagesDir, $realPath); if (!$path) { throw new \Exception("file not in images dir"); } $pubDir = ROOT_DIR . "/public"; $pubPath = ROOT_DIR . "/public/" . $fileDir; $realPubPath = FileSystem::inDir($pubDir, $pubPath, false); if (!$realPubPath) { throw new \Exception("Path not allow {$pubPath} in {$pubDir}"); } $pubPath = $realPubPath . "/" . $template . "/" . $fileName; $imp = $this->getImageProcessor(); $imp->process($realPath, $pubPath, $template); //TODO use accel Header::mime($pubPath); echo file_get_contents($pubPath); }
public function getMime() { if (is_null($this->mime)) { $this->mime = FS::getFileType($this->path); } return $this->mime; }
public function IndexAction(array $params = []) { $template = $params["template"]; $fileDir = $params["directory"]; $fileName = $params["file"]; $filePath = $fileDir . "/" . $fileName; $imagesDir = $this->getConfig(["ImageProcessor", "directory"], "data/images"); $imagesDir = ROOT_DIR . "/" . $imagesDir; $realPath = ROOT_DIR . $filePath; $path = FileSystem::inDir($imagesDir, $realPath); if (!$path) { throw new \Exception("file not in images dir"); } $pubDir = ROOT_DIR . "/public"; $pubPath = ROOT_DIR . "/public" . $fileDir; $realPubPath = FileSystem::getSubDir($pubDir, $pubPath, false); if (!$realPubPath) { throw new \Exception("Path not allow {$pubPath} in {$pubDir}"); } $pubPath = "/" . $realPubPath . "/" . $template . "/" . $fileName; $outFullPath = ROOT_DIR . "/public/" . $pubPath; $imp = $this->getImageProcessor(); $outFile = $imp->process($realPath, $outFullPath, $template); //TODO use accel Header::accel($pubPath, $outFile); // echo file_get_contents($pubPath); }
public function getSavePath($ext = null, $currentPath = null) { $configPaths = []; if ($ext) { $configPaths[] = ["Attach", "filesPath", $ext]; } if ($currentPath) { $fileMime = FileSystem::getFileType($currentPath); $configPaths[] = ["Attach", "filesPath", $fileMime]; $fileType = FileSystem::getFileTypeConst($currentPath); $configPaths[] = ["Attach", "filesPath", $fileType]; } $configPaths[] = ["Attach", "filesPath", "default"]; $configPaths[] = ["Attach", "filesPath"]; $path = $this->getConfig()->getOneIs($configPaths); if (is_array($path)) { throw new \RuntimeException("Many option for file path available"); } return $path; }
public function checkType($type) { return FileSystem::checkType($this->getPath(), $type); }
protected function readMenuRaw($path, $default = []) { $menuData = FileSystem::getPhpConfig($path, null); if (empty($menuData)) { return $default; } $assocMenu = []; foreach ($menuData as $key => $menu) { foreach ($menu as $item) { if (isset($item["link"])) { $assocMenu[$key][$item["link"]] = $item; } } } return $assocMenu; }
public function processAssets($files, $filters = null, $debug = false) { $webPatches = []; if ($debug) { $ac = $this->loadAssets($files, $filters, $debug); /*$fc = new FilterCollection([ new CssEmbedFilter() ]);*/ /** @var FileAsset $asset */ foreach ($ac as $asset) { $filePath = $asset->getSourceDirectory(); if (false !== ($subDir = FileSystem::getSubDir($this->getPublicDir(), $filePath))) { $subDir = !empty($subDir) ? $subDir . DIRECTORY_SEPARATOR : ""; $webPatches[] = $this->getWebPublic() . DIRECTORY_SEPARATOR . $subDir . basename($asset->getSourcePath()); } else { $filePath = $this->writeAsset($asset); $subDir = FileSystem::getSubDir($this->getOutputDir(), dirname($filePath)); $subDir = !empty($subDir) ? $subDir . DIRECTORY_SEPARATOR : ""; $webPatches[] = $this->getWebOutput() . DIRECTORY_SEPARATOR . $subDir . basename($filePath); } } } else { throw new \LogicException("Only debug mode support"); //получили коллекцию ассетов /* $fileName = hash("md5", implode('|', $files)) . "css"; $pubDir = $this->getOutputDir(); $filePath = $pubDir . DIRECTORY_SEPARATOR . $fileName; $ac = $this->loadAssets($files, $filters, $debug);*/ //фильтры } return $webPatches; }