cachePath() public method

Accessor for getting the cachePath for a given extension.
public cachePath ( string $ext, string $path = null )
$ext string Extension to get paths for.
$path string The path to cache files using $ext to.
Beispiel #1
0
 public function __construct(Module $modules, Module\Loader $load)
 {
     $configs = new AssetConfig($this->configs);
     if (!($cache_path = config_item('cache_path'))) {
         $cache_path = FCPATH . 'asset/cache/';
         config_item('cache_path', $cache_path);
     }
     $configs->cachePath('js', $cache_path . 'js');
     $configs->cachePath('css', $cache_path . 'css');
     foreach ($modules->getList('module') as $module) {
         $configs->set('js.paths', $module->path . 'asset/scripts/**');
         $configs->set('css.paths', $module->path . 'asset/styles/**');
     }
     $this->factory = new Factory($configs);
 }
Beispiel #2
0
 /**
  * Create a single build target
  *
  * @param string $name The name of the target to build
  * @return MiniAsset\AssetTarget
  */
 public function target($name)
 {
     $ext = $this->config->getExt($name);
     $paths = $this->config->paths($ext, $name);
     $themed = $this->config->isThemed($name);
     $filters = $this->config->targetFilters($name);
     $target = $this->config->cachePath($ext) . $name;
     $files = [];
     $scanner = $this->scanner($paths);
     foreach ($this->config->files($name) as $file) {
         if (preg_match('#^https?://#', $file)) {
             $files[] = new Remote($file);
         } else {
             if (preg_match('/(.*\\/)(\\*.*?)$/U', $file, $matches)) {
                 $path = $scanner->find($matches[1]);
                 if ($path === false) {
                     throw new RuntimeException("Could not locate folder {$file} for {$name} in any configured path.");
                 }
                 $glob = new Glob($path, $matches[2]);
                 $files = array_merge($files, $glob->files());
             } elseif (preg_match(static::CALLBACK_PATTERN, $file, $matches)) {
                 $callback = new Callback($matches[1], $matches[2], $scanner);
                 $files = array_merge($files, $callback->files());
             } else {
                 $path = $scanner->find($file);
                 if ($path === false) {
                     throw new RuntimeException("Could not locate {$file} for {$name} in any configured path.");
                 }
                 $files[] = new Local($path);
             }
         }
     }
     return new AssetTarget($target, $files, $filters, $paths, $themed);
 }
 /**
  * clear the builds for a specific extension.
  *
  * @return void
  */
 protected function _clearBuilds()
 {
     $themes = (array) $this->config->general('themes');
     if ($themes) {
         $this->config->theme($themes[0]);
     }
     $assets = $this->factory->assetCollection();
     if (count($assets) === 0) {
         $this->err('No build targets defined, skipping');
         return;
     }
     $targets = array_map(function ($target) {
         return $target->name();
     }, iterator_to_array($assets));
     $this->_clearPath(CACHE . 'asset_compress' . DS, $themes, $targets);
     $this->_clearPath($this->config->cachePath('js'), $themes, $targets);
     $this->_clearPath($this->config->cachePath('css'), $themes, $targets);
 }
 /**
  * Returns the build name for a requested asset
  *
  * @param \MiniAsset\AssetConfig $config The config object to use.
  * @param string $url The url to get an asset name from.
  * @return bool|string false if no build can be parsed from URL
  * with url path otherwise
  */
 protected function getName($config, $url)
 {
     $parts = explode('.', $url);
     if (count($parts) < 2) {
         return false;
     }
     $path = $config->cachePath($parts[count($parts) - 1]);
     if (empty($path)) {
         return false;
     }
     $root = str_replace('\\', '/', WWW_ROOT);
     $path = str_replace('\\', '/', $path);
     $path = str_replace($root, '', $path);
     if (strpos($url, $path) !== 0) {
         return false;
     }
     return str_replace($path, '', $url);
 }