/** * @dataProvider constructorAndGetterDataProvider */ public function testConstructorAndGetter($url, $expected_scheme, $expected_host, $expected_path, $expected_query, $expected_fragment, $expected_params) { $url_parser = new UrlParser($url); $this->assertEquals($expected_scheme, $url_parser->getComponent('scheme')); $this->assertEquals($expected_host, $url_parser->getComponent('host')); $this->assertEquals($expected_path, $url_parser->getComponent('path')); $this->assertEquals($expected_query, $url_parser->getComponent('query')); $this->assertEquals($expected_fragment, $url_parser->getComponent('fragment')); $this->assertEquals($expected_params, $url_parser->getParams()); }
/** * Builds united array of params from given $url and $params. Also extracts anchor. * * @param string $url The given absolute or relative url. * @param array $params Additional GET params. * @param string $base_url The base url. * * @throws UrlBuilderException When the path of the given url is empty or a base url is missing. */ public function __construct($url, array $params = array(), $base_url = null) { $url_parser = new UrlParser($base_url); $url_parser->merge(new UrlParser($url)); $this->path = $url_parser->getComponent('path'); $this->host = $url_parser->getComponent('host'); $this->protocol = $url_parser->getComponent('scheme'); $this->anchor = $url_parser->getComponent('fragment'); if (empty($this->path)) { throw new UrlBuilderException('URL path is missing', UrlBuilderException::TYPE_EMPTY_PATH); } if (empty($this->host)) { throw new UrlBuilderException('No base url specified', UrlBuilderException::TYPE_MISSING_BASE_URL); } $this->params = array_merge($url_parser->getParams(), $params); }