/** * @param string $url * * @throws \InvalidArgumentException If $urlString is not a string * @throws \UnexpectedValueException If provided string is not a valid URL */ public function __construct($url) { TypeChecker::assertString($url, '$url'); $components = parse_url($url); if (!$components) { throw new UnexpectedValueException(sprintf('Provided URL is invalid. [Received: %s]', $url)); } $this->url = $url; $this->scheme = array_key_exists('scheme', $components) ? $components['scheme'] : null; $this->host = array_key_exists('host', $components) ? $components['host'] : null; $this->port = array_key_exists('port', $components) ? $components['port'] : null; $this->user = array_key_exists('user', $components) ? $components['user'] : null; $this->pass = array_key_exists('pass', $components) ? $components['pass'] : null; $this->path = array_key_exists('path', $components) ? $components['path'] : null; $this->path = array_key_exists('path', $components) ? $components['path'] : null; $this->query = array_key_exists('query', $components) ? $components['query'] : null; $this->fragment = array_key_exists('fragment', $components) ? $components['fragment'] : null; }
/** * UrlParser constructor. * * @param string $urlString * * @throws \InvalidArgumentException If argument is not a string. */ public function __construct($urlString) { TypeChecker::assertString($urlString, '$urlString'); $this->url = Normalizer::normalize(new Url($urlString)); }
/** * @expectedException \InvalidArgumentException */ public function testAssertIntThrowExceptionOnNonIntegerValue() { TypeChecker::assertInt('this is not an integer', '$varName'); }