protected function getCssContents() { /** @var HtmlThemeInterface $theme */ $theme = $this->theme; // check last modification $lastModification = 0; foreach ($theme->getHtmlCssDependencies() as $item) { $filename = $theme->getResourcesPath() . $item; if (file_exists($filename)) { $lastModification = max($lastModification, filemtime($filename)); } } // cache $cacheFile = sprintf('%s/ladybug_cache/theme/%s.css', sys_get_temp_dir(), $theme->getName()); $lastModificationCache = file_exists($cacheFile) ? filemtime($cacheFile) : -1; if ($lastModification > $lastModificationCache) { $pce = new \CssEmbed\CssEmbed(); $css = ''; foreach ($theme->getHtmlCssDependencies() as $item) { $file = $theme->getResourcesPath() . $item; $minCss = file_get_contents($file); $pce->setRootDir(dirname($file)); $css .= $pce->embedString($minCss); } if (!is_dir(dirname($cacheFile))) { mkdir(dirname($cacheFile)); } file_put_contents($cacheFile, $css); } else { $css = file_get_contents($cacheFile); } return $css; }