/**
  * @param ResourceLoaderContext $context
  * @return array
  */
 public function getStyles(ResourceLoaderContext $context)
 {
     $styles = [];
     foreach ($this->getPages($context) as $titleText => $options) {
         if ($options['type'] !== 'style') {
             continue;
         }
         $media = isset($options['media']) ? $options['media'] : 'all';
         $style = $this->getContent($titleText);
         if (strval($style) === '') {
             continue;
         }
         if ($this->getFlip($context)) {
             $style = CSSJanus::transform($style, true, false);
         }
         $style = MemoizedCallable::call('CSSMin::remap', [$style, false, $this->getConfig()->get('ScriptPath'), true]);
         if (!isset($styles[$media])) {
             $styles[$media] = [];
         }
         $style = ResourceLoader::makeComment($titleText) . $style;
         $styles[$media][] = $style;
     }
     return $styles;
 }
 /**
  * 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
  *
  * @return string CSS data in script file
  * @throws MWException If the file doesn't exist
  */
 protected function readStyleFile($path, $flip, $context)
 {
     $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') {
         $style = $this->compileLessFile($localPath, $context);
         $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 MemoizedCallable::call('CSSMin::remap', array($style, $localDir, $remoteDir, true));
 }
Пример #3
0
 /**
  * @covers MemoizedCallable::call
  */
 public function testShortcutMethod()
 {
     $this->assertEquals('this is correct', MemoizedCallable::call('sprintf', ['this is %s', 'correct']));
 }