aggregatedFileCollector = $aggregatedFileCollector; $this->domMerger = $domMerger; $this->cache = $cache; $this->readerFactory = $readerFactory; $this->aggregatedFileCollectorFactory = $aggregatedFileCollectorFactory; $cachedTemplates = $this->cache->load(static::CACHE_ID); $this->cachedTemplates = $cachedTemplates === false ? [] : unserialize($cachedTemplates); } /** * Get template content * * @param string $template * @return string * @throws \Exception */ public function getTemplate($template) { $hash = sprintf('%x', crc32($template)); if (isset($this->cachedTemplates[$hash])) { return $this->cachedTemplates[$hash]; } $this->domMerger->unsetDom(); $this->cachedTemplates[$hash] = $this->readerFactory->create( [ 'fileCollector' => $this->aggregatedFileCollectorFactory->create(['searchPattern' => $template]), 'domMerger' => $this->domMerger ] )->getContent(); $this->cache->save(serialize($this->cachedTemplates), static::CACHE_ID); return $this->cachedTemplates[$hash]; } }