Пример #1
0
/**
 * Expands a URI template
 *
 * @param string $template  URI template
 * @param array  $variables Template variables
 *
 * @return string
 */
function uri_template($template, array $variables)
{
    if (extension_loaded('uri_template')) {
        // @codeCoverageIgnoreStart
        return \uri_template($template, $variables);
        // @codeCoverageIgnoreEnd
    }
    static $uriTemplate;
    if (!$uriTemplate) {
        $uriTemplate = new UriTemplate();
    }
    return $uriTemplate->expand($template, $variables);
}
Пример #2
0
 /**
  * Expands a URI template
  *
  * @param string $template  URI template
  * @param array  $variables Template variables
  *
  * @return string
  */
 function uri_template($template, array $variables)
 {
     if (function_exists('\\uri_template')) {
         /** @noinspection PhpUndefinedFunctionInspection */
         return \uri_template($template, $variables);
     }
     static $uriTemplate;
     if (!$uriTemplate) {
         $uriTemplate = new UriTemplate();
     }
     return $uriTemplate->expand($template, $variables);
 }
 /**
  * @ticket https://github.com/guzzle/guzzle/issues/90
  */
 public function testAllowsNestedArrayExpansion()
 {
     $template = new UriTemplate();
     $result = $template->expand('http://example.com{+path}{/segments}{?query,data*,foo*}', array('path' => '/foo/bar', 'segments' => array('one', 'two'), 'query' => 'test', 'data' => array('more' => array('fun', 'ice cream')), 'foo' => array('baz' => array('bar' => 'fizz', 'test' => 'buzz'), 'bam' => 'boo')));
     $this->assertEquals('http://example.com/foo/bar/one,two?query=test&more%5B0%5D=fun&more%5B1%5D=ice%20cream&baz%5Bbar%5D=fizz&baz%5Btest%5D=buzz&bam=boo', $result);
 }
Пример #4
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.');
 }
Пример #5
0
 public function build() : RequestInterface
 {
     $uriTemple = new UriTemplate();
     $criteria = [];
     foreach ($this->criteria as $key => $value) {
         $criteria[] = $key;
         $criteria[] = $value;
     }
     $uri = $uriTemple->expand('{schema}://{host}/api{/series}{/season}{/round}{/criteria*}/{select}{/id}{.format}{?limit,offset}', ['schema' => $this->schema, 'host' => $this->host, 'series' => $this->series, 'season' => $this->season, 'round' => $this->round, 'criteria' => $criteria, 'select' => $this->select, 'id' => $this->id, 'format' => empty($this->select) ? null : $this->format, 'limit' => $this->limit, 'offset' => $this->offset]);
     return new Request('Get', $uri);
 }
Пример #6
0
/**
 * Expands a URI template
 *
 * @param string $template  URI template
 * @param array  $variables Template variables
 *
 * @return string
 */
function uri_template($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);
}
 /**
  * Process the URI template using the supplied variables
  *
  * @param string $template  URI Template to expand
  * @param array  $variables Variables to use with the expansion
  *
  * @return string Returns the expanded template url
  */
 public function process($template, array $variables)
 {
     return $this->_processor->expand($template, $variables);
 }