/** * $path_parts = [0]=>assets_path; [1]=>filename; [2]=>extension; */ public function __construct($file, Base $parentParser = null) { if (!$file instanceof File) { $extension = pathinfo($file, PATHINFO_EXTENSION); $file = new File($extension, $file); } $this->file = $file; if (!isset(self::$_first_parents[$file->extension()])) { self::$_first_parents[$file->extension()] = $this; } $this->parentParser = $parentParser; $this->firstParent()->add_required_file($file); }
protected function compileOtherFiles() { $exts = $this->filePatterns; $pattern = '{' . implode(',', $exts) . '}'; $foundFiles = []; foreach ($this->paths as $assetsRoot) { $foundFiles = array_merge($foundFiles, Rails\Toolbox\FileTools::searchFile($assetsRoot, $pattern, GLOB_BRACE)); } $files = []; $assetsPath = $this->compilePath() . $this->prefix(); foreach ($foundFiles as $foundFile) { $file = new File($foundFile); $contents = file_get_contents($foundFile); $this->createCompiledFile($assetsPath . '/' . $file->relative_path(), $contents, false); if ($this->config()->digest) { $md5 = md5_file($foundFile); $relativeDir = $file->relative_dir(); if ($relativeDir) { $relativeDir .= '/'; } $relativePath = $relativeDir . $file->file_root(); $basePath = $this->compilePath() . $this->prefix(); $fileroot = $basePath . '/' . $relativeDir . $file->file_root(); # Delete previous md5 files $pattern = $fileroot . '-*.' . $ext . '*'; if ($mfiles = glob($pattern)) { $regexp = '/-' . $md5 . '\\.' . $ext . '(\\.gz)?$/'; foreach ($mfiles as $mfile) { if (!preg_match($regexp, $mfile)) { unlink($mfile); } } } $this->updateManifestIndex($relativePath . '.' . $ext, $relativePath . '-' . $md5 . '.' . $ext); $md5File = $file->relative_file_root_path() . '-' . $md5 . '.' . $file->type(); $this->createCompiledFile($assetsPath . '/' . $md5File, $contents, false); } } }