You are here

public function ScssphpCompiler::checkLastModifyTime in SCSS/Less Compiler 8

Checks if file was changed.

Parameters

array $source_file: Compilation file info.

Return value

string Last modify timestamp.

Overrides ScssCompilerPluginInterface::checkLastModifyTime

File

src/Plugin/ScssCompiler/ScssphpCompiler.php, line 131

Class

ScssphpCompiler
Plugin implementation of the Scss compiler.

Namespace

Drupal\scss_compiler\Plugin\ScssCompiler

Code

public function checkLastModifyTime(array &$source_file) {
  $last_modify_time = filemtime($source_file['source_path']);
  $source_folder = dirname($source_file['source_path']);
  $import = [];
  $content = file_get_contents($source_file['source_path']);
  preg_match_all('/@import(.*);/', $content, $import);
  if (!empty($import[1])) {
    foreach ($import[1] as $file) {

      // Normalize @import path.
      $file_path = trim($file, '\'" ');
      $pathinfo = pathinfo($file_path);
      $extension = '.scss';
      $filename = $pathinfo['filename'];
      $dirname = $pathinfo['dirname'] === '.' ? '' : $pathinfo['dirname'] . '/';
      $file_path = $source_folder . '/' . $dirname . $filename . $extension;
      $scss_path = $source_folder . '/' . $dirname . '_' . $filename . $extension;
      if (file_exists($file_path) || file_exists($file_path = $scss_path)) {
        $file_modify_time = filemtime($file_path);
        if ($file_modify_time > $last_modify_time) {
          $last_modify_time = $file_modify_time;
        }
      }
    }
  }
  return $last_modify_time;
}