Example #1
0
 /**
  * Less constructor.
  * @param $file
  * @param $cache
  */
 public function __construct($file, $cache)
 {
     Utilities::setHeader('Content-Type', 'text/css');
     $this->file = $file;
     $this->cache = $cache;
     return $this;
 }
Example #2
0
 /**
  * @return string
  */
 public function getFile()
 {
     // No point in storing in cache since no parsing is done
     $contents = Utilities::getFile($this->file['path']);
     // fix absolute paths
     $contents = str_replace(array('../'), str_replace(ROOT, "", dirname($this->file['path'])) . '/../', $contents);
     return $contents;
 }
Example #3
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;
 }
Example #4
0
 /**
  * @return string
  */
 public function getFile()
 {
     // No point in caching js files since no parsing is done
     return Utilities::getFile($this->file['path']);
 }
Example #5
0
 /**
  * @return $this
  */
 public function setHeaders()
 {
     $lastModifiedDate = $this->last_modified;
     $eTag = hash('sha256', $lastModifiedDate . $this->file_data['hash']);
     $checkModifiedSince = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
     $checkETag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
     if ($checkModifiedSince && strtotime($checkModifiedSince) == $lastModifiedDate || $checkETag == $eTag) {
         Utilities::statusCode(304, 'Not Modified');
         $this->modified = true;
     } else {
         $maxage = 60 * 60 * 24 * 320;
         // Avoid the hard limit some servers have
         Utilities::setHeader('Cache-Control', 'max-age=' . $maxage . ', must-revalidate');
         Utilities::setHeader('Pragma', 'cache');
         Utilities::setHeader('Last-Modified', date('D, d M Y H:i:s', $lastModifiedDate) . ' GMT');
         Utilities::setHeader('Expires', date('D, d M Y H:i:s', time() + 60 * 60 * 24 * 90) . ' GMT');
         Utilities::statusCode(200, 'OK');
     }
     return $this;
 }