Ejemplo n.º 1
0
 /**
  * @param $inputFilename
  * @param null $outputFilename
  *
  * @return string
  *
  * @todo add typehinting
  */
 public function compileFile($inputFilename, $outputFilename = null)
 {
     if (!$this->prepareEnvironment($inputFilename)) {
         return $inputFilename;
     }
     if ($outputFilename === null) {
         $outputFilename = PATH_site . $this->cachePath . basename($inputFilename);
     }
     $outputFilenamePathInfo = pathinfo($outputFilename);
     $noExtensionFilename = $outputFilename . '-' . hash('crc32b', $inputFilename) . '-' . hash('crc32b', serialize($this->overrides)) . '-' . hash('crc32b', filemtime($inputFilename));
     $preparedFilename = $noExtensionFilename . '.' . $outputFilenamePathInfo['extension'];
     $cacheFilename = $noExtensionFilename . '.cache';
     $outputFilename = $noExtensionFilename . '.css';
     $this->inputFilename = $inputFilename;
     $this->outputFilename = $outputFilename;
     $this->cacheFilename = $cacheFilename;
     // exit if a precompiled version already exists
     if (file_exists($outputFilename) && (!ApplicationContext::isDevelopmentModeActive() && !$this->config['enableDebugMode'])) {
         return $outputFilename;
     }
     //write intermediate file, if the source has been changed, the rest is done by the cache management
     if (@filemtime($preparedFilename) < @filemtime($inputFilename) || $this->_checkIfCompileNeeded($inputFilename)) {
         file_put_contents($preparedFilename, $this->_prepareCompile(file_get_contents($inputFilename)));
         $fileContent = $this->_postCompile($this->_compileFile($inputFilename, $preparedFilename, $outputFilename, $cacheFilename));
         if ($fileContent !== false) {
             file_put_contents($outputFilename, $fileContent);
             // important for some cache clearing scenarios
             if (file_exists($preparedFilename)) {
                 unlink($preparedFilename);
             }
         }
     }
     return $outputFilename;
 }
 /**
  * @return bool
  */
 public static function isDevelopmentModeActive()
 {
     $applicationContext = new ApplicationContext();
     return $applicationContext->isDevelopmentApplicationContext() || $applicationContext->isDevelopPresetActive();
 }