getParsedFiles() public méthode

Returns list of parsed files
public getParsedFiles ( ) : array
Résultat array
 /**
  * Compile .scss file
  *
  * @param string $in  Input path (.scss)
  * @param string $out Output path (.css)
  *
  * @return array
  */
 protected function compile($in, $out)
 {
     $start = microtime(true);
     $css = $this->scss->compile(file_get_contents($in), $in);
     $elapsed = round(microtime(true) - $start, 4);
     $v = Version::VERSION;
     $t = @date('r');
     $css = "/* compiled by scssphp {$v} on {$t} ({$elapsed}s) */\n\n" . $css;
     $etag = md5($css);
     file_put_contents($out, $css);
     file_put_contents($this->metadataName($out), serialize(array('etag' => $etag, 'imports' => $this->scss->getParsedFiles())));
     return array($css, $etag);
 }
Exemple #2
0
 /**
  * @param array $sourceFiles
  * @param string $outputFile
  * @return array
  */
 protected function compile($sourceFiles, $outputFile)
 {
     $parsedFiles = [];
     $file = fopen($outputFile, 'w');
     foreach ($sourceFiles as $sourceFile) {
         $compiler = new Compiler();
         $compiler->addImportPath(dirname($sourceFile));
         fwrite($file, $compiler->compile(file_get_contents($sourceFile), $sourceFile) . "\n");
         fflush($file);
         $parsedFiles = array_merge($parsedFiles, $compiler->getParsedFiles());
     }
     fclose($file);
     return $parsedFiles;
 }
Exemple #3
0
 public static function compileFile(string $file, array $paths, string $formatter, bool $lineComments) : array
 {
     $location = static::resolveFile($file, $paths);
     $compiler = new Compiler();
     $compiler->setImportPaths(\dirname($location));
     $compiler->addImportPath(function (string $path) use($paths) {
         return static::resolveFile($path, $paths);
     });
     $compiler->setFormatter($formatter);
     if ($lineComments) {
         $compiler->setLineNumberStyle(Compiler::LINE_COMMENTS);
     }
     $css = $compiler->compile(\file_get_contents($location), $location);
     return [$css, $compiler->getParsedFiles()];
 }
Exemple #4
0
 /**
  * @return string
  */
 public function getFile()
 {
     // get file contents
     $file_contents = Utilities::getFile($this->file['path']);
     // Create scss parser
     $scss = new Compiler();
     // set load path for imported files
     $scss->setImportPaths(dirname($this->file['path']));
     // Parse file using direct file path
     $contents = $scss->compile($file_contents);
     // fix absolute file paths
     $contents = str_replace(array('../'), str_replace(ROOT, "", dirname($this->file['path'])) . '/../', $contents);
     // get parsed files and store in cache
     $this->cache->save($this->file['hash'] . "parsed_files", $scss->getParsedFiles());
     // return css
     return $contents;
 }
 /**
  * {@inheritdoc}
  */
 public function compile($path, $relativePath)
 {
     $this->parsedFiles = array();
     $scss = new Compiler();
     $scss->setFormatter('Leafo\\ScssPhp\\Formatter\\Compressed');
     if (!empty($this->importDirs)) {
         $scss->setImportPaths($this->importDirs);
     }
     $content = $this->overrideVariables();
     $content .= '@import "' . $relativePath . '";' . "\n";
     $css = $scss->compile($content);
     $parsedFiles = array();
     foreach ($scss->getParsedFiles() as $file => $time) {
         $parsedFiles[] = $file;
     }
     $this->parsedFiles = $parsedFiles;
     return $css;
 }
Exemple #6
0
 /**
  * Callback method called before filters are run
  *
  * Overriding to run the file through LESS/SCSS if need be.
  * Also want to fix any relative paths for images.
  *
  * @param string $originalFile
  * @param string $cacheFile
  *
  * @throws CompilationException
  */
 protected function beforeFilter($originalFile, $cacheFile)
 {
     if ($this->isLess($originalFile)) {
         $less = new lessc();
         try {
             $compiledLess = $less->cachedCompile($originalFile);
         } catch (\Exception $e) {
             throw new CompilationException('Error in LESS Compiler', 0, $e);
         }
         $compiledLess['compiled'] = $this->fixRelativePaths($compiledLess['compiled'], $originalFile);
         file_put_contents($cacheFile, serialize($compiledLess));
     } elseif ($this->isScss($originalFile)) {
         $scss = new ScssCompiler();
         $scss->addImportPath(pathinfo($originalFile, PATHINFO_DIRNAME));
         try {
             $compiled = $scss->compile(file_get_contents($originalFile));
         } catch (\Exception $e) {
             throw new CompilationException('Error in SCSS Compiler', 0, $e);
         }
         $content = compact('compiled');
         $parsedFiles = $scss->getParsedFiles();
         $parsedFiles[] = $originalFile;
         foreach ($parsedFiles as $file) {
             $content['files'][$file] = filemtime($file);
         }
         $content['compiled'] = $this->fixRelativePaths($content['compiled'], $originalFile);
         file_put_contents($cacheFile, serialize($content));
     } else {
         $content = file_get_contents($originalFile);
         file_put_contents($cacheFile, $this->fixRelativePaths($content, $originalFile));
     }
 }
Exemple #7
0
 /**
  * Compile .scss file
  *
  * @param string $filename Input path (.scss)
  *
  * @see Server::compile()
  * @return array meta data result of the compile
  */
 private function compile($filename)
 {
     $start = microtime(true);
     $scss = new Compiler();
     // set import path directory the input filename resides
     // otherwise @import statements will not find the files
     // and will treat the @import line as css import
     $scss->setImportPaths(dirname($filename));
     $css = $scss->compile(file_get_contents($filename), $filename);
     $elapsed = round(microtime(true) - $start, 4);
     $v = Version::VERSION;
     $ts = date('r', $start);
     $css = "/* compiled by scssphp {$v} on {$ts} ({$elapsed}s) */\n\n" . $css;
     $imports = $scss->getParsedFiles();
     $updated = 0;
     foreach ($imports as $mtime) {
         $updated = max($updated, $mtime);
     }
     return array('elapsed' => $elapsed, 'updated' => $updated, 'content' => $css, 'files' => $imports);
 }