Ejemplo n.º 1
0
 public function rewriteCssUrls($content)
 {
     $urlRegex = '`url\\((.*?)\\)`s';
     $newContent = preg_replace_callback($urlRegex, function ($matches) {
         if (strpos($matches[0], '//') !== false) {
             return $matches[0];
         }
         $baseUrl = new Url($this->cdnBaseUrl);
         $existingUrl = new Url($matches[1]);
         $newUrl = new Url();
         $newUrl->setHost($baseUrl->getHost());
         if ($baseUrl->isSchemeless()) {
             $newUrl->makeSchemeless();
         } else {
             $newUrl->setScheme($baseUrl->getScheme());
         }
         if (count($baseUrl->getPath())) {
             $newUrl->setPath($baseUrl->getPath());
             $newUrl->getPath()->appendPath($existingUrl->getPath());
         } else {
             $newUrl->setPath($existingUrl->getPath());
         }
         $newUrl->getPath()->setEncoder(false);
         $newUrl->setQuery($existingUrl->getQuery());
         return "url(" . $newUrl->__toString() . ")";
     }, $content);
     return $newContent;
 }
Ejemplo n.º 2
0
 public function testSchemelessUrls()
 {
     $url = new \Swurl\Url('/foo/bar.jpg');
     $url->makeSchemeless();
     $this->assertEquals('/foo/bar.jpg', $url->__toString());
     $url->setHost('example.com');
     $this->assertEquals('//example.com/foo/bar.jpg', $url->__toString());
     $url->setScheme('http');
     $this->assertEquals('http://example.com/foo/bar.jpg', $url->__toString());
     $url = new Url("//foo.com/bar/bar.jpg");
     $this->assertTrue($url->isSchemeless());
     $this->assertEquals('//foo.com/bar/bar.jpg', $url->__toString());
     $url->setScheme('http');
     $this->assertEquals('http://foo.com/bar/bar.jpg', $url->__toString());
 }