/** * Reads a style file. * * This method can be used as a callback for array_map() * * @param string $path File path of style file to read * @param bool $flip * @param ResourceLoaderContext $context (optional) * * @return string CSS data in script file * @throws MWException If the file doesn't exist */ protected function readStyleFile($path, $flip, $context = null) { $localPath = $this->getLocalPath($path); $remotePath = $this->getRemotePath($path); if (!file_exists($localPath)) { $msg = __METHOD__ . ": style file not found: \"{$localPath}\""; wfDebugLog('resourceloader', $msg); throw new MWException($msg); } if ($this->getStyleSheetLang($localPath) === 'less') { $compiler = $this->getLessCompiler($context); $style = $this->compileLessFile($localPath, $compiler); $this->hasGeneratedStyles = true; } else { $style = file_get_contents($localPath); } if ($flip) { $style = CSSJanus::transform($style, true, false); } $localDir = dirname($localPath); $remoteDir = dirname($remotePath); // Get and register local file references $localFileRefs = CSSMin::getAllLocalFileReferences($style, $localDir); foreach ($localFileRefs as $file) { if (file_exists($file)) { $this->localFileRefs[] = $file; } else { $this->missingLocalFileRefs[] = $file; } } return CSSMin::remap($style, $localDir, $remoteDir, true); }
/** * CSSMin::getAllLocalFileReferences should ignore url(...) expressions * that have been commented out. */ public function testCommentedLocalFileReferences() { $basepath = __DIR__ . '/../data/css/'; $css = file_get_contents($basepath . 'comments.css'); $files = CSSMin::getAllLocalFileReferences($css, $basepath); $expected = array($basepath . 'not-commented.gif'); $this->assertArrayEquals($expected, $files, 'Url(...) expression in comment should be omitted.'); }