Пример #1
0
 /**
  * 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);
 }
Пример #2
0
 /**
  * @dataProvider mergeDataProvider
  */
 public function testMerge($first_url, $second_url, $expected_component, $expected_value)
 {
     $url_parser = new UrlParser($first_url);
     $url_parser->merge(new UrlParser($second_url));
     $this->assertEquals($expected_value, $url_parser->getComponent($expected_component));
 }