Esempio n. 1
0
 /**
  * @When /^I follow the "([^"]+)" uri template HAL link with the following parameters:$/
  */
 public function iFollowTheXUriTemplateLinkWithTheFollowingParameters($rel, TableNode $table)
 {
     $parameters = array();
     foreach ($table->getHash() as $rows) {
         foreach ($rows as $key => $value) {
             if (preg_match('/\\[\\]$/', $key)) {
                 $parameters[$key][] = $value;
             } else {
                 $parameters[$key] = $value;
             }
         }
     }
     $parameters = array_map(function ($value) {
         return is_array($value) ? array_filter($value) : $value;
     }, $parameters);
     $parameters = array_combine(array_map('urlencode', array_keys($parameters)), array_values($parameters));
     $uriTemplateParser = new UriTemplate();
     $href = $uriTemplateParser->expand(JsonUtil::getJsonPath($this, sprintf('[\'_links\'][\'%s\'][\'href\']', $rel)), $parameters);
     return array(new When(sprintf('I go to "%s"', $href)));
 }
 /**
  * Expands a URL template with the $variables and returns the result.
  *
  * @param string $resourceName
  * @param array  $variables
  *
  * @return mixed|string
  */
 protected function getResourceUrl($resourceName, array $variables = array())
 {
     $template = $this->uriTemplates[$resourceName];
     $uriTemplate = new UriTemplate();
     $path = $uriTemplate->expand($template, $variables);
     $url = rtrim(static::$baseUrl, '/') . '/' . ltrim($path, '/');
     return $url;
 }
Esempio n. 3
0
 /**
  * Prepare the url with variables.
  *
  * @param array $variables Required if the link is templated
  *
  * @return string
  *
  * @throws \RuntimeException When call with property "href" empty
  */
 private function prepareUrl(array $variables = array())
 {
     if (null === $this->href) {
         throw new \RuntimeException('Href must to be sets.');
     }
     if (!$this->templated) {
         return $this->href;
     }
     $template = new UriTemplate();
     return $template->expand($this->href, $variables);
 }
Esempio n. 4
0
 /**
  * @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);
 }
Esempio n. 5
0
 /**
  * @ticket https://github.com/guzzle/guzzle/issues/426
  */
 public function testSetRegex()
 {
     $template = new UriTemplate();
     $template->setRegex('/\\<\\$(.+)\\>/');
     $this->assertSame('/foo', $template->expand('/<$a>', array('a' => 'foo')));
 }