public function asset($resource = null, $params = []) { # http://example.com/app/images/foo.jpg $template = new UriTemplate($this->getBaseUrl(false)); $resource = '/' . ltrim($resource, '/'); return $template->expand($resource, $params); }
/** * Render a templated uri with the given parameters * * @param string $templatedUri Templated URI that match RFC6570 * @param array $parameters * @return string */ protected function renderUri($templatedUri, $parameters = array()) { return $this->uriTemplater->expand($templatedUri, $parameters); }
<?php require 'vendor/autoload.php'; require 'parser.php'; use Rize\UriTemplate; use Goutte\Client; $uri = new UriTemplate(); $client = new Client(); $parser = new Parser(); $url = $uri->expand('http://www.idchips.com/fr/recherche?search_identification_number={id}', ['id' => '999999999999999']); $crawler = $client->request('GET', $url); $content = $crawler->filter('div#content > table'); $text = null; $html = null; if (!empty($content)) { try { if (!empty($node = $content->eq(0))) { $text = $node->text(); $html = $node->html(); } } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } } //echo $text; $html = $parser->removeAttributes($html); echo $html;
/** * @param string $uri * @param array $variables * @return string * @todo look at returning UriInterface */ public function expandUri($uri, array $variables) { $template = new UriTemplate(); return $template->expand($uri, $variables); }
/** * Create a complete API Uri from the Base Uri, path and query parameters. * * Example: * Given a base uri that equal http://domain.tld * Given the following parameters /pets/{id}, ['id' => 1], ['foo' => 'bar'] * Then the Uri will equal to http://domain.tld/pets/1?foo=bar * * @param string $pathTemplate A template path * @param array $pathParameters Path parameters * @param array $queryParameters Query parameters * * @return UriInterface */ private function buildRequestUri($pathTemplate, array $pathParameters, array $queryParameters) { $path = $this->uriTemplate->expand($pathTemplate, $pathParameters); $query = http_build_query($queryParameters); return $this->baseUri->withPath($path)->withQuery($query); }