Ejemplo n.º 1
0
 /**
  * Parses url
  *
  * @param  string $url Url to parse
  * @return Url    Object representation of url
  */
 public function parseUrl($url)
 {
     $elem = array('scheme' => null, 'user' => null, 'pass' => null, 'host' => null, 'port' => null, 'path' => null, 'query' => null, 'fragment' => null);
     if (preg_match(self::SCHEME_PATTERN, $url) === 0) {
         $url = 'http://' . preg_replace('#^//#', '', $url, 1);
     }
     $parts = pdp_parse_url($url);
     if ($parts === false) {
         throw new \InvalidArgumentException(sprintf('Invalid url %s', $url));
     }
     $elem = (array) $parts + $elem;
     $host = $this->parseHost($parts['host']);
     return new Url($elem['scheme'], $elem['user'], $elem['pass'], $host, $elem['port'], $elem['path'], $elem['query'], $elem['fragment']);
 }
Ejemplo n.º 2
0
 /**
  * Parses url.
  *
  * @param string $url Url to parse
  *
  * @return Url Object representation of url
  */
 public function parseUrl($url)
 {
     $elem = array('scheme' => null, 'user' => null, 'pass' => null, 'host' => null, 'port' => null, 'path' => null, 'query' => null, 'fragment' => null);
     if (preg_match(self::SCHEME_PATTERN, $url) === 0) {
         // Wacky scheme required to overcome parse_url behavior in PHP lt 5.4.7
         // See https://github.com/jeremykendall/php-domain-parser/issues/49
         $url = 'php-lt-5.4.7-hack://' . preg_replace('#^//#', '', $url, 1);
     }
     $parts = pdp_parse_url($url);
     if ($parts === false) {
         throw new \InvalidArgumentException(sprintf('Invalid url %s', $url));
     }
     if ($parts['scheme'] === 'php-lt-5.4.7-hack') {
         // Remove wacky scheme required to overcome parse_url behavior in PHP lt 5.4.7
         // See https://github.com/jeremykendall/php-domain-parser/issues/49
         $parts['scheme'] = null;
     }
     $elem = (array) $parts + $elem;
     $host = $this->parseHost($parts['host']);
     return new Url($elem['scheme'], $elem['user'], $elem['pass'], $host, $elem['port'], $elem['path'], $elem['query'], $elem['fragment']);
 }
Ejemplo n.º 3
0
 /**
  * Parses url.
  *
  * @param string $url Url to parse
  *
  * @return Url Object representation of url
  */
 public function parseUrl($url)
 {
     $rawUrl = $url;
     $elem = array('scheme' => null, 'user' => null, 'pass' => null, 'host' => null, 'port' => null, 'path' => null, 'query' => null, 'fragment' => null);
     if (preg_match(self::SCHEME_PATTERN, $url) === 0) {
         // Wacky scheme required to overcome parse_url behavior in PHP lt 5.4.7
         // See https://github.com/jeremykendall/php-domain-parser/issues/49
         $url = 'php-lt-5.4.7-hack://' . preg_replace('#^//#', '', $url, 1);
     }
     $parts = pdp_parse_url($url);
     if ($parts === false) {
         throw new SeriouslyMalformedUrlException($rawUrl);
     }
     if ($parts['scheme'] === 'php-lt-5.4.7-hack') {
         // Remove wacky scheme required to overcome parse_url behavior in PHP lt 5.4.7
         // See https://github.com/jeremykendall/php-domain-parser/issues/49
         $parts['scheme'] = null;
     }
     /** @noinspection AdditionOperationOnArraysInspection */
     $elem = (array) $parts + $elem;
     $host = $this->parseHost($parts['host']);
     return new Url($elem['scheme'], $elem['user'], $elem['pass'], $host, $elem['port'], $elem['path'], $elem['query'], $elem['fragment']);
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider parseDataProvider
  * @covers ::pdp_parse_url
  *
  * @param $url
  * @param $publicSuffix
  * @param $registrableDomain
  * @param $subdomain
  * @param $hostPart
  */
 public function testpdp_parse_urlCanReturnCorrectHost($url, $publicSuffix, $registrableDomain, $subdomain, $hostPart)
 {
     $this->assertEquals($hostPart, pdp_parse_url('http://' . $hostPart, PHP_URL_HOST));
 }