public function expand($template, array $variables)
 {
     return uri_template($template, $variables);
 }
Exemple #2
0
 private static function expandUriTemplate($template, $variables)
 {
     static $guzzleUriTemplate;
     if (function_exists('\\uri_template')) {
         // @codeCoverageIgnoreStart
         return \uri_template($template, $variables);
         // @codeCoverageIgnoreEnd
     }
     if (class_exists('\\GuzzleHttp\\UriTemplate')) {
         if (!$guzzleUriTemplate) {
             $guzzleUriTemplate = new \GuzzleHttp\UriTemplate();
         }
         return $guzzleUriTemplate->expand($template, $variables);
     }
     throw new \RuntimeException('Could not detect supported method for expanding URI templates. ' . 'You should either provide a global \\uri_template function ' . '(e.g. by installing the uri_template extension from ' . 'https://github.com/ioseb/uri-template) or by installing the ' . 'guzzlehttp/guzzle package (version ~5.0 or ~6.0) via Composer.');
 }
Exemple #3
0
 /**
  * Expands a URI template
  *
  * @param string $template  URI template
  * @param array  $variables Template variables
  *
  * @return string
  */
 public static function uriTemplate($template, array $variables)
 {
     if (function_exists('\\uri_template')) {
         return \uri_template($template, $variables);
     }
     static $uriTemplate;
     if (!$uriTemplate) {
         $uriTemplate = new UriTemplate();
     }
     return $uriTemplate->expand($template, $variables);
 }
 public function expand($template, array $variables)
 {
     /** @noinspection PhpUndefinedFunctionInspection */
     return uri_template($template, $variables);
     //Someone still uses PECL?
 }
Exemple #5
0
 /**
  * Expands a URI template
  *
  * @param string $template  URI template
  * @param array  $variables Template variables
  *
  * @return string
  */
 function puzzle_uri_template($template, array $variables)
 {
     if (function_exists('uri_template')) {
         return uri_template($template, $variables);
     }
     static $uriTemplate;
     if (!$uriTemplate) {
         $uriTemplate = new puzzle_UriTemplate();
     }
     return $uriTemplate->expand($template, $variables);
 }
Exemple #6
0
 public function testFormStyleContinuationExpansion()
 {
     $variables = $this->_expression_expension_variables;
     $templates = array('{&who}' => "&who=fred", '{&half}' => "&half=50%25", '?fixed=yes{&x}' => "?fixed=yes&x=1024", '{&x,y,empty}' => "&x=1024&y=768&empty=", '{&x,y,undef}' => "&x=1024&y=768", '{&var:3}' => "&var=val", '{&list}' => "&list=red,green,blue", '{&list*}' => "&list=red&list=green&list=blue", '{&keys}' => "&keys=semi,%3B,dot,.,comma,%2C", '{&keys*}' => "&semi=%3B&dot=.&comma=%2C");
     foreach ($templates as $template => $expected) {
         $value = uri_template($template, $variables);
         $this->assertEquals($expected, $value);
     }
 }
 /**
  * @param array $body
  * @param array $links
  * @param Hal   $hal
  *
  * @internal param Uri $uri
  */
 private function getHalLink(array $body, array $links, Hal $hal)
 {
     foreach ($links as $link) {
         if (!$link instanceof Link) {
             continue;
         }
         $uri = uri_template($link->href, $body);
         $reverseUri = $this->getReverseMatchedLink($uri);
         $hal->addLink($link->rel, $reverseUri);
     }
 }
Exemple #8
0
 /**
  * Call handler that actually queues a data fetch and returns a promise
  *
  * @param string $method The API's "path" element to ascend into
  * @param array $args Array of arguments forwarded to \seekat\API::get()
  * @return ExtendedPromiseInterface
  */
 function __call(string $method, array $args) : ExtendedPromiseInterface
 {
     /* We cannot implement an explicit then() method,
      * because the Promise implementation might think
      * we're actually implementing Thenable,
      * which might cause an infinite loop.
      */
     if ($method === "then") {
         return $this->get()->then(...$args);
     }
     /*
      * very short-hand version:
      * ->users->m6w6->gists->get()->then(...)
      * vs:
      * ->users->m6w6->gists(...)
      */
     if (is_callable(current($args))) {
         return $this->{$method}->get()->then(current($args));
     }
     /* standard access */
     if ($this->exists($method)) {
         return $this->{$method}->get(...$args);
     }
     /* fetch resource, unless already localized, and try for {$method}_url */
     return $this->{$method}->get(...$args)->otherwise(function ($error) use($method, $args) {
         if ($error instanceof Throwable) {
             $message = $error->getMessage();
         } else {
             $message = $error;
             $error = new Exception($error);
         }
         if ($this->exists($method . "_url", $url)) {
             $this->__log->info(__FUNCTION__ . "({$method}): " . $message, ["url" => (string) $this->__url]);
             $url = new Url(uri_template($url, (array) current($args)));
             return $this->withUrl($url)->get(...$args);
         }
         $this->__log->error(__FUNCTION__ . "({$method}): " . $message, ["url" => (string) $this->__url]);
         throw $error;
     });
 }