Пример #1
0
 public function testSetGetParams()
 {
     $url_parser = new Parser('http://domain.tld/path?param=value#anchor');
     $updated_params = array('param' => 'value', 'new_param' => 'new_value');
     $this->assertEquals(array('param' => 'value'), $url_parser->getParams());
     $url_parser->setParams($updated_params);
     $this->assertEquals($updated_params, $url_parser->getParams());
     $this->assertEquals(http_build_query($updated_params), $url_parser->getComponent('query'));
 }
Пример #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 query params.
  *
  * @param MatchUrlComponentAnnotation $annotation The annotation.
  * @param Parser                      $parser     Parser instance to match against.
  *
  * @return boolean
  */
 protected function matchParams(MatchUrlComponentAnnotation $annotation, Parser $parser)
 {
     // Not specified means match anything.
     if (!isset($annotation->params)) {
         return true;
     }
     return $parser->getParams() == $annotation->params;
 }