示例#1
0
 /**
  * Creates an Uri object using the given URI components.
  *
  * Authority part will be overwritten by provided user info, host and port.
  *
  * @param string|null $scheme The URI scheme
  * @param string|null $authority The authority part
  * @param string|null $userInfo The user info part
  * @param string|null $host The host name
  * @param int|null $port The protocol port
  * @param string|null $path The path part
  * @param string|null $query The query part
  * @param string|null $fragment The fragment
  * @throws \Ableron\Core\Exception\SystemException
  * @return \Ableron\Lib\Net\Uri
  */
 public static function createFromComponents($scheme = null, $authority = null, $userInfo = null, $host = null, $port = null, $path = null, $query = null, $fragment = null)
 {
     try {
         $uri = new Uri();
         $uri->setScheme($scheme);
         $uri->setAuthority($authority);
         if ($userInfo !== null) {
             $uri->setUserInfo($userInfo);
         }
         if ($host !== null) {
             $uri->setHost($host);
         }
         if ($port !== null) {
             $uri->setPort($port);
         }
         $uri->setPath($path);
         $uri->setQuery($query);
         $uri->setFragment($fragment);
         return $uri;
     } catch (SystemException $e) {
         throw new SystemException('Unable to create Uri object', 0, E_USER_NOTICE, __FILE__, __LINE__, $e);
     }
 }
示例#2
0
 /**
  * Tests whether setPort() works as expected.
  *
  * @dataProvider dataProviderTestSetPort
  * @return void
  */
 public function testSetPort($inputPort, $expectedPort)
 {
     $uri = new Uri();
     $uri->setPort($inputPort);
     $this->assertSame($expectedPort, $uri->getPort());
 }