Ejemplo n.º 1
0
 /**
  * Parses the string and returns the {@link Uri}.
  * 
  * Parses the string and returns the {@link Uri}. If parsing fails, null is returned.
  * 
  * @param String $string The url.
  * 
  * @return \Bumble\Uri\Uri The Uri object.
  */
 public function parse($string)
 {
     $data = parse_url($string);
     //helper function gets $a[$k], checks if exists
     function get($a, $k)
     {
         if (array_key_exists($k, $a)) {
             return empty($a[$k]) ? null : $a[$k];
         }
         return null;
     }
     if ($data === null) {
         return null;
     }
     $uri = new Uri();
     $uri->setProtocol(get($data, 'scheme'));
     $uri->setUsername(get($data, 'user'));
     $uri->setPassword(get($data, 'pass'));
     $uri->setHost(get($data, 'host'));
     $uri->setPort(get($data, 'port'));
     $uri->setPath(get($data, 'path'));
     $uri->setQuery(get($data, 'query'));
     $uri->setAnchor(get($data, 'anchor'));
     return $uri;
 }
Ejemplo n.º 2
0
 public function testSetGetHost()
 {
     $host = 'somenewhost';
     $this->uri->setHost($host);
     $this->assertEquals($host, $this->uri->getHost());
 }