Example #1
0
 /**
  * Sends the asset straight to the browser and exits
  *
  * @return void
  * @throws SynergyException
  */
 public function deliver()
 {
     if ((isset($this->filename) || isset($this->contents)) && isset($this->contentType)) {
         if (Project::isDev()) {
             $aHeaders = array('Expires' => date('r', strtotime('Yesterday')), 'Cache-Control' => 'no-store, no-cache, max-age=0, must-revalidate', 'Pragma' => 'no-cache');
         } else {
             $aHeaders = array('Expires' => date('r', strtotime('+5 min')), 'Cache-Control' => 'private, max-age=300, must-revalidate', 'Pragma' => 'private');
         }
         // Important headers
         if (isset($this->filename) && !isset($this->contents)) {
             $aHeaders['X-Filename'] = $this->filename;
             $aHeaders['Last-Modified'] = date('r', filectime($this->filename));
             $aHeaders['ETag'] = md5(filectime($this->filename));
             $aHeaders['Content-Length'] = filesize($this->filename);
         } else {
             $aHeaders['Last-Modified'] = date('r');
             $aHeaders['Content-Length'] = strlen($this->contents);
         }
         $this->aHeaders = array_merge($aHeaders, $this->aHeaders);
         $this->sendHeaders();
         if (isset($this->filename) && !isset($this->contents)) {
             $fp = fopen($this->filename, 'rb');
             fpassthru($fp);
             exit;
         } else {
             die($this->contents);
         }
     }
     throw new SynergyException('Invalid init of WebAsset, unable to deliver');
 }