/** * Converts the ruleset to CSS. Applies the output filters to the output. * * @param ILess_Node_Ruleset $ruleset * @param array $variables * @return string The generated CSS code */ protected function toCSS(ILess_Node_Ruleset $ruleset, array $variables) { // the cache key consists of: // 1) parsed rules // 2) assigned variables via the API // 3) environment options $cacheKey = $this->generateCacheKey(serialize($this->rules) . serialize($variables) . serialize(array($this->env->compress, $this->env->sourceMap, $this->env->sourceMapOptions, $this->env->relativeUrls, $this->env->precision, $this->env->debug, $this->env->dumpLineNumbers, $this->env->canShortenColors, $this->env->ieCompat, $this->env->strictMath, $this->env->strictUnits))); $rebuild = true; if ($this->cache->has($cacheKey)) { $rebuild = false; list($css, $importedFiles) = $this->cache->get($cacheKey); // we need to check if the file has been modified foreach ($importedFiles as $importedFileArray) { list($lastModifiedBefore, $path, $currentFileInfo) = $importedFileArray; $lastModified = $this->importer->getLastModified($path, $currentFileInfo); if ($lastModifiedBefore != $lastModified) { $rebuild = true; // no need to continue, we will rebuild the CSS break; } } } if ($rebuild) { $css = parent::toCSS($ruleset, $variables); // what have been imported? $importedFiles = array(); foreach ($this->importer->getImportedFiles() as $importedFile) { // we need to save original path, last modified timestamp and currentFileInfo object // see ILess_Importer::setImportedFile() $importedFiles[] = array($importedFile[0]->getLastModified(), $importedFile[1], $importedFile[2]); } $this->cache->set($cacheKey, array($css, $importedFiles)); } return $this->filter($css); }