Exemple #1
0
 /**
  * @param $path
  * @param string $includeDir
  * @param \Less\Environment|null $env
  */
 public function __construct($path, $includeDir = '', $env = null)
 {
     $this->_path = $path;
     // The '.less' extension is optional
     if ($path instanceof \Less\Node\Quoted) {
         $this->path = preg_match('/\\.(le?|c)ss(\\?.*)?$/', $path->value) ? $path->value : $path->value . '.less';
     } else {
         $this->path = isset($path->value->value) ? $path->value->value : $path->value;
     }
     $this->css = preg_match('/css(\\?.*)?$/', $this->path);
     // Only pre-compile .less files
     if (!$this->css) {
         $less = $includeDir . '/' . $this->path;
         $parser = new \Less\Parser($env);
         $this->root = $parser->parseFile($less, true);
     }
 }
Exemple #2
0
    $files[$key] = pathinfo($file, PATHINFO_BASENAME);
    if (!file_exists($files[$key])) {
        unset($files[$key]);
    }
    if (pathinfo($file, PATHINFO_EXTENSION) != 'less') {
        unset($files[$key]);
    }
}
if (count($files)) {
    // Check for a cached version of the query string hash
    $hash = md5(array_reduce($files, function ($a, $b) {
        return $a . $b . filemtime($b);
    }));
    if (!file_exists($cachePath . $hash)) {
        // Parse the selected files
        $parser = new \Less\Parser($env);
        foreach ($files as $file) {
            try {
                $parser->parseFile($file);
            } catch (\Exception $e) {
                // Skip errors for now
            }
        }
        file_put_contents($cachePath . $hash, $parser->getCss());
    }
    $modTime = filemtime($cachePath . $hash);
    // Send 304 header if appropriate
    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'], $_SERVER['SERVER_PROTOCOL'])) {
        if ($modTime <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
            header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
            exit;