예제 #1
0
 /**
  * Resolves this relative URI using the given absolute base URI.
  *
  * Does not change this Uri object in case this URI is already absolute.
  *
  * @param \Ableron\Lib\Net\Uri $baseUri The absolute base URI used to resolve this relative URI
  * @throws \Ableron\Core\Exception\SystemException
  * @return \Ableron\Lib\Net\Uri
  */
 public function resolve(Uri $baseUri)
 {
     // check whether base URI is absolute
     if (!$baseUri->isAbsolute()) {
         throw new SystemException(sprintf('Unable to resolve URI using base URI "%s" - Base URI must be absolute!', $baseUri->toString()), 0, E_USER_NOTICE, __FILE__, __LINE__);
     }
     // check whether URI is already absolute
     if ($this->isAbsolute()) {
         $this->setPath(self::removeDotSegments($this->path));
         return $this;
     }
     // resolve scheme specific part
     if ($this->host !== null) {
         $this->setPath(self::removeDotSegments($this->path));
     } else {
         // resolve authority part
         $this->setUserInfo($baseUri->getRawUserInfo());
         $this->setHost($baseUri->getRawHost());
         $this->setPort($baseUri->getPort());
         // resolve path and query
         if ($this->path === '') {
             $this->setPath($baseUri->getRawPath());
             if ($this->query === null) {
                 $this->setQuery($baseUri->getRawQuery());
             }
         } else {
             if (StringUtil::startsWith($this->path, '/')) {
                 $this->setPath(self::removeDotSegments($this->path));
             } else {
                 $this->setPath(self::removeDotSegments($baseUri->getRawHost() !== null && $baseUri->getRawPath() === '' ? '/' : StringUtil::getSubstring($baseUri->getRawPath(), 0, StringUtil::getLastIndexOf($baseUri->getRawPath(), '/') + 1) . $this->path));
             }
         }
     }
     // resolve scheme
     $this->setScheme($baseUri->getScheme());
     // return reference of this object
     return $this;
 }
예제 #2
0
 /**
  * Tests whether setScheme() works as expected.
  *
  * @dataProvider dataProviderTestSetScheme
  * @return void
  */
 public function testSetScheme($inputScheme, $expectedScheme)
 {
     $uri = new Uri();
     $uri->setScheme($inputScheme);
     $this->assertSame($expectedScheme, $uri->getScheme());
 }