public function compileCSS($request, $response) { $buffer = $this->resolveData($request->get('data')); $compiler = new Compiler\CSSCompiler(); return new Response($compiler->compile($buffer['source'], WEB_PATH . $buffer['target']), array('content-type' => 'text/css')); }
public function compile($type, $source, $options = array(), $force = false) { if ($this->isGroup($source)) { $grouping = true; $targetFileName = $source; } else { $grouping = false; $targetFileName = md5($this->templatingService->getContext() . $source); } $targetUri = ($type === 'js' ? $this->jsPath : $this->cssPath) . AssetResolver::resolveNameWithVersion($targetFileName, $type, $this->version, $this->versionFormat); $doCompilation = false; if ($this->enableCompilation) { if ($grouping) { $sourcePath = $this->getGroupAssetPath($type, $this->groups[$type][$source]); } else { $sourcePath = $this->getAssetPath($source); } $targetFilePath = WEB_PATH . AssetResolver::resolveNameForCompilation($targetUri); if ($force || $this->forceCompilation) { $doCompilation = true; } elseif ($this->enableCompilation) { if (!file_exists($targetFilePath)) { $doCompilation = true; } elseif ($grouping) { foreach ($sourcePath as $source) { $m = filemtime($targetFilePath); if (filemtime($source) > $m) { $doCompilation = true; break; } } } elseif (filemtime($sourcePath) > filemtime($targetFilePath)) { $doCompilation = true; } } if ($doCompilation) { if ($type === 'js') { $compiler = new Compiler\JSCompiler($options); } elseif ($type === 'css') { $compiler = new Compiler\CSSCompiler($options); } if ($grouping) { $compiler->compileGroup($sourcePath, $targetFilePath); } else { $compiler->compile($sourcePath, $targetFilePath); } } } return $targetUri; }