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; }
public function testHostWithPort() { $url = new \Swurl\Url('http://www.example.com:8080'); $this->assertTrue($url->getHost()->hasPort()); $this->assertEquals(8080, $url->getHost()->getPort()); }