Пример #1
0
 /**
  * Private method for building the URL object
  *
  * @return \r8\URL
  */
 private function buildURL()
 {
     $url = new \r8\URL();
     // Get the url Scheme from the server protocol
     if (self::hasKey($this->server, "SERVER_PROTOCOL")) {
         $url->setScheme(strtolower(strstr($this->server['SERVER_PROTOCOL'], "/", TRUE)));
     }
     // Pull the server host, if it is set
     if (self::hasKey($this->server, 'HTTP_HOST')) {
         $url->setHost($this->server['HTTP_HOST']);
     } else {
         if (self::hasKey($this->server, "SERVER_ADDR")) {
             $url->setHost($this->server['SERVER_ADDR']);
         }
     }
     // Pull the port
     if (self::hasKey($this->server, "SERVER_PORT")) {
         $url->setPort((int) $this->server['SERVER_PORT']);
     }
     // The path and file name
     if (self::hasKey($this->server, 'SCRIPT_NAME')) {
         $url->setPath($this->server['SCRIPT_NAME']);
     }
     // The faux directories
     if (self::hasKey($this->server, 'PATH_INFO')) {
         $url->setFauxDir(\r8\str\head($this->server['PATH_INFO'], "/"));
     }
     // Finally, pull the the URL query
     if (self::hasKey($this->server, 'QUERY_STRING')) {
         $url->setQuery($this->server['QUERY_STRING']);
     }
     return $url;
 }
Пример #2
0
 public function testGetURL()
 {
     $url = new \r8\URL();
     $this->assertNull($url->getURL());
     $url->setBase("http://www.example.com/");
     $this->assertSame("http://www.example.com", $url->getURL());
     $url->setPath("/path/to/file.php");
     $this->assertSame("http://www.example.com/path/to/file.php", $url->getURL());
     $url->setQuery("one=single")->setFragment("frag");
     $this->assertSame("http://www.example.com/path/to/file.php?one=single#frag", $url->getURL());
 }