/** * @param $id * * @return AssetsLoader\Application\AssetResponse|Application\Responses\TextResponse */ public function actionAssets($id) { if (NULL === ($item = $this->assetCache->getItem(Utils\Strings::webalize($id)))) { return new Application\Responses\TextResponse(''); } return new AssetsLoader\Application\AssetResponse($item[Caching\AssetCache::CONTENT], $item[Caching\AssetCache::CONTENT_TYPE], $item[Caching\AssetCache::ETAG]); }
/** * Load content and save file * * @param Entities\IFile[] $files * @param string $contentType * * @return Utils\ArrayHash */ public function generate(array $files, $contentType) { // Init vars $name = $this->getFilename($files); $hash = $this->getHash($files); $lastModified = $this->getLastModified($files); if ($this->cache->load($hash) === NULL) { $before = memory_get_peak_usage(); $content = $this->getContent($files); // Add compiled files into diagnostics panel if ($this->debugPanel) { $this->debugPanel->addFile($files, $hash, $this->type, $lastModified, memory_get_peak_usage() - $before); } $this->cache->save($hash, [Caching\AssetCache::CONTENT_TYPE => $contentType, Caching\AssetCache::CONTENT => $content], [Caching\AssetCache::TAGS => ['ipub.assetsloader', 'ipub.assetsloader.assets'], Caching\AssetCache::FILES => array_keys($files)]); } return Utils\ArrayHash::from(['file' => $name, 'hash' => $hash, 'lastModified' => $lastModified, 'sourceFiles' => $files]); }