Exemple #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;
 }
Exemple #2
0
 public function testIsSameBase()
 {
     $url = new \r8\URL();
     $compare = new \r8\URL("http://www.example.edu:80");
     $this->assertFalse($url->isSameBase($compare));
     $url->setScheme("http");
     $this->assertFalse($url->isSameBase($compare));
     $url->setPort(80);
     $this->assertFalse($url->isSameBase($compare));
     $url->setHost("example.edu");
     $this->assertTrue($url->isSameBase($compare));
     $url->clearPort();
     $this->assertTrue($url->isSameBase($compare));
 }