コード例 #1
0
ファイル: UrlRewriter.php プロジェクト: jimbojsb/simple-asset
 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;
 }
コード例 #2
0
ファイル: UrlTest.php プロジェクト: jimbojsb/swurl
 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());
 }
コード例 #3
0
ファイル: UrlTest.php プロジェクト: jimbojsb/swurl
 public function testHostWithPort()
 {
     $url = new \Swurl\Url('http://www.example.com:8080');
     $this->assertTrue($url->getHost()->hasPort());
     $this->assertEquals(8080, $url->getHost()->getPort());
 }