Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function parse($uri)
 {
     $uriParser = new UriParser();
     $uriParser->setMode(UriParser::MODE_IDNA2003);
     $uri = $uriParser->parse($uri);
     if (null === $uri) {
         throw new RuntimeException('`Riimu\\Kit\\UrlParser\\UriParser::parse` returns `null`');
     }
     return $this->formatResults(['scheme' => $uri->getScheme(), 'userinfo' => $uri->getUserInfo(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'query' => $uri->getQuery(), 'fragment' => $uri->getFragment()]);
 }
Ejemplo n.º 2
0
 /**
  * Creates a new instance of Uri.
  * @param string $uri The URI provided as a string or empty string for none
  * @param int $mode The parser mode used to parse the provided URI
  * @throws \InvalidArgumentException If the provided URI is invalid
  */
 public function __construct($uri = '', $mode = UriParser::MODE_RFC3986)
 {
     $uri = (string) $uri;
     if ($uri !== '') {
         $parser = new UriParser();
         $parser->setMode($mode);
         $parsed = $parser->parse($uri);
         if (!$parsed instanceof self) {
             throw new \InvalidArgumentException("Invalid URI '{$uri}'");
         }
         $properties = get_object_vars($parsed);
         array_walk($properties, function ($value, $name) {
             $this->{$name} = $value;
         });
     }
 }