/**
  * Get a built file.  Use query parameters for dynamic builds.
  * for dynamic builds to work, you must be in debug mode, and not have the same
  * build file already defined.
  */
 public function get($build)
 {
     $Config = $this->_getConfig();
     if (isset($this->params['url']['ext']) && in_array($this->params['url']['ext'], $Config->extensions())) {
         $build .= '.' . $this->params['url']['ext'];
     }
     if (isset($this->params['url']['theme'])) {
         $Config->theme($this->params['url']['theme']);
     }
     // dynamic build file
     if (Configure::read('debug') > 0 && $Config->files($build) === array()) {
         $files = array();
         if (isset($this->params['url']['file'])) {
             $files = $this->params['url']['file'];
         }
         $Config->files($build, $files);
     }
     try {
         $Compiler = new AssetCompiler($Config);
         $contents = $Compiler->generate($build);
         if ($Config->cachingOn($build)) {
             $Cache = new AssetCache($Config);
             $Cache->write($build, $contents);
         }
     } catch (Exception $e) {
         $this->log($e->getMessage());
         $this->header('HTTP/1.1 404 Not Found');
         $this->autoRender = false;
         return;
     }
     $this->header('Content-Type: ' . $this->_getContentType($Config->getExt($build)));
     $this->set('contents', $contents);
     $this->render('contents');
 }
 public function testIsFreshConfigExpire()
 {
     touch(TMP . '/libs.js');
     $data = parse_ini_file($this->testConfig, true);
     $constants = array('TEST_FILES' => $this->_testFiles);
     $config = new AssetConfig($data, $constants, strtotime('-1 minute'));
     $config->cachePath('js', TMP);
     $config->set('js.timestamp', false);
     $cache = new AssetCache($config);
     $this->assertTrue($cache->isFresh('libs.js'));
     $config = new AssetConfig($data, $constants, strtotime('+1 minute'));
     $config->cachePath('js', TMP);
     $config->set('js.timestamp', false);
     $cache = new AssetCache($config);
     $this->assertFalse($cache->isFresh('libs.js'));
     unlink(TMP . '/libs.js');
 }
 /**
  * Returns css for the given path
  * 
  * @return \Illuminate\Support\Facades\Response
  */
 private function stylesheet($path)
 {
     $response = Response::make('', 304);
     if (!AssetCache::hasValidEtag($path)) {
         $response = Response::make(AssetCache::stylesheets($path), 200);
     }
     $response->header('Content-Type', 'text/css');
     $response->setEtag(AssetCache::getEtag($path));
     return $response;
 }
 /**
  * Get the build file name.
  *
  * Generates filenames that are intended for production use
  * with statically generated files.
  *
  * @param string $build The build being resolved.
  * @return string The resolved build name.
  */
 protected function _getBuildName($build)
 {
     $config = $this->config();
     $ext = $config->getExt($build);
     $hash = $this->_getHashName($build, $ext);
     if ($hash) {
         $build = $hash;
     }
     $config->theme($this->theme);
     return $this->_AssetCache->buildFileName($build);
 }
Example #5
0
 /**
  * Generate and save the cached file for a build target.
  *
  * @param string $build The build to generate.
  * @return void
  */
 protected function _buildTarget($build)
 {
     $this->out('Saving file for ' . $build);
     $Compiler = new AssetCompiler($this->_Config);
     $Cacher = new AssetCache($this->_Config);
     try {
         $contents = $Compiler->generate($build);
         $Cacher->write($build, $contents);
     } catch (Exception $e) {
         $this->err('Error: ' . $e->getMessage());
     }
 }
 /**
  * Store the last time this file was modified (which we don't know)
  * so we just use the current datetime. We will store this date in
  * $_SESSION so that next time we run we can re-use the datetime we
  * first picked so that our cache isn't busted each time.
  *
  * @param  string $key
  * @return string
  */
 private function getLastTimeModified($key)
 {
     return filemtime($this->asset->getSourceRoot() . '/' . $this->asset->getSourcePath());
 }