public function __construct(WebRequest $request)
 {
     parent::__construct($request);
     $files = explode(',', $this->mOid);
     foreach ($files as $file) {
         // fake single SASS file request
         $sassRequest = new WebRequest();
         $sassRequest->setVal('type', 'sass');
         $sassRequest->setVal('oid', $file);
         $builder = new AssetsManagerSassBuilder($sassRequest);
         $this->mContent .= "\n\n/* {$file} */\n" . $builder->getContent();
     }
     $this->mContentType = AssetsManager::TYPE_CSS;
 }
 public static function serve(WebRequest $request)
 {
     try {
         switch ($request->getText('type')) {
             case 'one':
                 $builder = new AssetsManagerOneBuilder($request);
                 break;
             case 'group':
                 $builder = new AssetsManagerGroupBuilder($request);
                 break;
             case 'groups':
                 $builder = new AssetsManagerGroupsBuilder($request);
                 break;
             case 'sass':
                 $builder = new AssetsManagerSassBuilder($request);
                 break;
             default:
                 Wikia::log(__METHOD__, false, "Unknown type: {$_SERVER['REQUEST_URI']}", true);
                 Wikia::log(__METHOD__, false, AssetsManager::getRequestDetails(), true);
                 throw new Exception('Unknown type.');
         }
     } catch (Exception $e) {
         header('HTTP/1.1 404 Not Found');
         echo $e->getMessage();
         return;
     }
     $headers = array();
     if ($builder->getContentType()) {
         $headers['Content-Type'] = $builder->getContentType();
     }
     // BugId:31327
     $headers['Vary'] = $builder->getVary();
     $cacheDuration = $builder->getCacheDuration();
     if ($cacheDuration > 0) {
         $headers['Expires'] = gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime($cacheDuration . ' seconds'));
         $headers['X-Pass-Cache-Control'] = $builder->getCacheMode() . ', max-age=' . $cacheDuration;
         $headers['Cache-Control'] = $builder->getCacheMode() . ', max-age=' . $cacheDuration;
     }
     $headers['Last-Modified'] = gmdate('D, d M Y H:i:s \\G\\M\\T');
     foreach ($headers as $k => $v) {
         header($k . ': ' . $v);
     }
     echo $builder->getContent();
 }
 /**
  * @group Slow
  * @slowExecutionTime 0.85936 ms
  */
 public function testSassBuilder()
 {
     // disable memcache layer in this test
     $mock_memc = $this->getMock('stdClass', array('get', 'set'));
     $mock_memc->expects($this->any())->method('get')->will($this->returnValue(false));
     $mock_memc->expects($this->any())->method('set')->will($this->returnValue(true));
     $this->mockGlobalVariable('wgMemc', $mock_memc);
     $request = new WebRequest();
     $request->setVal('oid', self::SASS_FILE);
     $request->setVal('cb', $this->cb);
     $builder = new AssetsManagerSassBuilder($request);
     $this->assertContains('#foo', $builder->getContent());
     // test URLs rewriting
     $this->assertContains('sprite.png', $builder->getContent());
     $this->assertContains("{$this->cdn}/skins/shared/images/sprite.png", $builder->getContent());
     $this->assertNotContains('/* $wgCdnStylePath */', $builder->getContent());
     // test base64 encoding
     $this->assertNotContains('blank.gif', $builder->getContent());
     $this->assertContains('data:image/gif;base64,', $builder->getContent());
     $this->assertNotContains('/* base64 */', $builder->getContent());
 }
 /**
  * Tries to base64 encode images marked with "base64" comment
  */
 private function base64Processing()
 {
     wfProfileIn(__METHOD__);
     $this->mContent = preg_replace_callback("/([, ]url[^\n]*?)(\\s*\\/\\*\\s*base64\\s*\\*\\/)/is", function ($matches) {
         global $IP;
         $fileName = $IP . trim(substr($matches[1], 4, -1), '\'"() ');
         $encoded = AssetsManagerSassBuilder::base64EncodeFile($fileName);
         if ($encoded !== false) {
             return "url({$encoded});";
         } else {
             throw new Exception("/* Base64 encoding failed: {$fileName} not found! */");
         }
     }, $this->mContent);
     wfProfileOut(__METHOD__);
 }