/**
  * Populate $resource with values for parameters witch the implementations is interested in.
  *
  * @param ResourceInterface $resource
  * @return mixed
  */
 public function populate(ResourceInterface $resource)
 {
     if (!count($this)) {
         return;
     }
     $self = $this;
     $url = preg_replace_callback(self::PARAM_REGEXP, function ($matches) use($self) {
         $name = $matches['name'];
         return $self->has($name) ? $self->get($name)->getValue() : null;
     }, $resource->getUrl());
     // update resource with $url values
     $resource->setUrl($url);
 }
 /**
  * Populate $resource with values for parameters witch the implementations is interested in.
  *
  * @param ResourceInterface $resource
  * @return mixed
  */
 public function populate(ResourceInterface $resource)
 {
     if (!count($this)) {
         return;
     }
     $url = $resource->getUrl();
     $query = parse_url($url, PHP_URL_QUERY);
     if (!$query) {
         return;
     }
     $url = str_replace($query, null, $url);
     $query = array();
     foreach ($this as $param) {
         $query[$param->getName()] = $param->getValue();
     }
     $url = trim($url);
     $url = rtrim($url, '?') . '?';
     $url .= http_build_query($query);
     // update resource with $url values
     $resource->setUrl($url);
 }
Ejemplo n.º 3
0
 public function toArrayResource(ResourceInterface $resource)
 {
     return array('method' => $resource->getMethod(), 'url' => $resource->getUrl(), 'description' => $resource->getDescription(), 'urlParams' => $this->toArrayParamSet($resource->getUrlParams()), 'queryParams' => $this->toArrayParamSet($resource->getQueryParams()));
 }