public function __construct(AssetManager $am, $name) { parent::__construct($am, $name); $this->assetName = $name; }
protected function assetic($files, $type) { $urls = []; foreach ($files as $key => $file) { $assetType = $this->parseInput($file); if ($assetType == 'http') { $urls[] = $file; unset($files[$key]); } } if (empty($files)) { return $urls; } $name = md5(implode(',', $files)) . '.' . $type; $cachePath = $this->config['paths']['pcache']; $cache = $this->config['paths']['cache']; $cachedFile = $this->config['locations']['cache'] . $name; $file = $cachePath . $name; $debug = $this->config['debug']; if (!$debug && file_exists($file)) { $urls[] = $cachedFile; return $urls; } $aw = new AssetWriter($cachePath); $am = new AssetManager(); // Create the collection $collection = new AssetCollection(); // Create the cache $cache = new FilesystemCache($cache); foreach ($files as $file) { $assetType = $this->parseInput($file); // Create the asset if ($assetType == 'file') { $asset = new FileAsset($file); } elseif ($assetType == 'glob') { $asset = new GlobAsset($file); } elseif ($assetType == 'http') { $asset = new HttpAsset($file); } elseif ($assetType == 'reference') { $asset = new AssetReference($am, substr($file, 1)); } $filters = $this->getFilters($file); if (!empty($filters)) { foreach ($filters as $filter) { // Add the filter $asset->ensureFilter($filter); } } // Cache the asset so we don't have to reapply filters on future page loads $cachedAsset = new AssetCache($asset, $cache); // Add the cached asset to the collection $collection->add($cachedAsset); } if (!file_exists($file) || $collection->getLastModified() > filemtime($file)) { $am->set($type, $collection); $am->get($type)->setTargetPath($name); $aw->writeManagerAssets($am); } $urls[] = $cachedFile; return $urls; }