コード例 #1
0
ファイル: IndexController.php プロジェクト: deltaphp/image
 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);
 }
コード例 #2
0
 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;
 }