public function loadCssAction()
{
$oFile = $this->jarves->getRootDir() . '/../web/cache/admin.style-compiled.css';
$md5String = '';
/** @var \Jarves\AssetHandler\Container $assetHandlerContainer */
$assetHandlerContainer = $this->container->get('jarves.asset_handler.container');
$files = [];
foreach ($this->jarves->getConfigs() as $bundleConfig) {
foreach ($bundleConfig->getAdminAssetsInfo() as $assetInfo) {
if (!$assetInfo->isCompressionAllowed()) {
continue;
}
if ($assetInfo->isStylesheet()) {
$path = $this->jarves->resolveWebPath($assetInfo->getPath());
if (file_exists($path)) {
$files[] = $assetInfo->getPath();
$md5String .= filemtime($path);
}
}
if ($assetInfo->isScss()) {
$path = $this->jarves->resolveWebPath($assetInfo->getPath());
if (file_exists($path)) {
foreach ($assetHandlerContainer->compileAsset($assetInfo) as $subAssetInfo) {
$files[] = $subAssetInfo->getPath();
}
$md5String .= filemtime($path);
}
}
}
}
$handle = @fopen($oFile, 'r');
$fileUpToDate = false;
$md5Line = '/* ' . md5($md5String) . "*/\n";
if ($handle) {
$line = fgets($handle);
fclose($handle);
if ($line == $md5Line) {
$fileUpToDate = true;
}
}
if (!$fileUpToDate) {
$content = $this->utils->compressCss($files, $this->jarves->getAdminPrefix() . 'admin/backend/');
$content = $md5Line . $content;
file_put_contents($oFile, $content);
}
$expires = 60 * 60 * 24 * 14;
$response = new Response(file_get_contents($oFile));
$response->headers->set('Content-Type', 'text/css');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'max-age=' . $expires);
$response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
return $response;
}