Пример #1
0
 /**
  * @dataProvider mergeDataProvider
  */
 public function testMerge($first_url, $second_url, array $expected_components)
 {
     $url_parser = new Parser($first_url);
     $url_parser->merge(new Parser($second_url));
     foreach ($expected_components as $expected_component => $expected_value) {
         $this->assertEquals($expected_value, $url_parser->getComponent($expected_component), 'The "' . $expected_component . '" has expected value.');
     }
 }
Пример #2
0
 /**
  * Returns normalized url.
  *
  * @param PageUrlAnnotation $annotation The page url annotation.
  *
  * @return array
  */
 public function normalize(PageUrlAnnotation $annotation)
 {
     $parser = new Parser($this->baseUrl);
     $parser->merge(new Parser($annotation->url));
     $parser->setParams(array_merge($parser->getParams(), $annotation->params));
     $ret = $parser->getComponents();
     if ($annotation->secure !== null && !empty($ret['scheme'])) {
         $ret['scheme'] = $annotation->secure ? 'https' : 'http';
     }
     return $ret;
 }
Пример #3
0
 /**
  * Merge both url parsers.
  *
  * @param Parser $parser The url parser to merge.
  *
  * @return self
  */
 public function merge(Parser $parser)
 {
     $left_path = $this->getComponent('path');
     $right_path = $parser->getComponent('path');
     $left_params = $this->getParams();
     $right_params = $parser->getParams();
     $this->components = array_merge($this->components, $parser->components);
     if ($left_path && $right_path) {
         $this->components['path'] = rtrim($left_path, '/') . '/' . ltrim($right_path, '/');
     }
     if ($left_params && $right_params) {
         $this->components['query'] = http_build_query(array_replace_recursive($left_params, $right_params));
     }
     return $this;
 }
Пример #4
0
 /**
  * Matches property.
  *
  * @param MatchUrlComponentAnnotation $annotation The annotation.
  * @param Parser                      $parser     Parser instance to match against.
  * @param string                      $property   Property name.
  * @param string|null                 $component  Component name.
  *
  * @return boolean
  */
 protected function matchByProperty(MatchUrlComponentAnnotation $annotation, Parser $parser, $property, $component = null)
 {
     // Not specified means match anything.
     if (!isset($annotation->{$property})) {
         return true;
     }
     return $parser->getComponent(isset($component) ? $component : $property) === $annotation->{$property};
 }
Пример #5
0
 /**
  * @dataProvider mergeDataProvider
  */
 public function testMerge($first_url, $second_url, $expected_component, $expected_value)
 {
     $url_parser = new Parser($first_url);
     $url_parser->merge(new Parser($second_url));
     $this->assertEquals($expected_value, $url_parser->getComponent($expected_component));
 }