public static function appendPath($url, $path) { $uri = new Psr7Uri($url); $cutUrl = (string) $uri->withQuery('')->withFragment(''); if ($path === '' || $path[0] === '#') { return $cutUrl . $path; } else { return rtrim($cutUrl, '/') . '/' . ltrim($path, '/'); } }
/** * @return \Psr\Http\Message\UriInterface */ public function getUri() { $uri = new Uri($this->serviceUri); return $uri->withQuery(\GuzzleHttp\Psr7\build_query($this->params)); }
public static function appendPath($url, $path) { $uri = new Psr7Uri($url); $cutUrl = (string) $uri->withQuery('')->withFragment(''); return rtrim($cutUrl, '/') . '/' . ltrim($path, '/'); }
/** * @param SpeechInfoInterface $speech source of url parameters * @return UriInterface */ public function generate(SpeechInfoInterface $speech) { $query = http_build_query(['uuid' => $speech->getUuid(), 'key' => $this->key, 'topic' => $speech->getTopic(), 'lang' => $speech->getLang()]); $request = new Uri($this->base); return $request->withQuery($query); }
/** * Get the URL for authentication. * * @param string $redirectUri * @param string $scope * @param null|string $state * @param bool $preferSignup * * @return string */ public function getAuthRequestUri($redirectUri, $scope = 'global', $state = null, $preferSignup = false) { $uri = new Uri(vsprintf('%s/oauth/auth', [$this->endpoint])); $query = ['scope' => $scope, 'redirect_uri' => $redirectUri, 'response_type' => static::OAUTH_RESPONSE_TYPE_CODE, 'client_id' => $this->clientId, 'access_type' => static::OAUTH_ACCESS_TYPE_OFFLINE]; if ($state) { $query['state'] = $state; } if ($preferSignup) { $query['prefer_signup'] = true; } return $uri->withQuery(http_build_query($query)); }
protected function getHeaderViewData($title, Request $request = null) { $session = $this->get('session'); $header = new Header($title); $header->stores = new Url($this->trans('header.stores'), ''); $header->help = new Url($this->trans('header.help'), ''); $header->callUs = new Url($this->trans('header.callUs', ['phone' => $this->config['sunrise.header.callUs']]), ''); $header->location = new ViewData(); $languages = new ViewDataCollection(); $routeParams = $request->get('_route_params'); $queryParams = \GuzzleHttp\Psr7\parse_query($request->getQueryString()); foreach ($this->config['languages'] as $language) { $languageEntry = new ViewData(); if ($language == \Locale::getPrimaryLanguage($this->locale)) { $languageEntry->selected = true; } $languageEntry->label = $this->trans('header.languages.' . $language); $routeParams['_locale'] = $language; $languageUri = $this->generateUrl($request->get('_route'), $routeParams); $uri = new Uri($languageUri); $languageEntry->value = (string) $uri->withQuery(\GuzzleHttp\Psr7\build_query($queryParams)); $languages->add($languageEntry); } $header->location->language = $languages; // $countries = new ViewDataCollection(); // foreach ($this->config['countries'] as $country) { // $countryEntry = new ViewData(); // $countryEntry->label = $this->trans('header.countries.' . $country); // $countryEntry->value = $country; // $countries->add($countryEntry); // } // // $header->location->country = $countries; $header->user = new ViewData(); $header->user->isLoggedIn = false; $header->user->signIn = new Url('Login', ''); $header->miniCart = new ViewData(); $header->miniCart->totalItems = $session->get('cartNumItems', 0); $header->navMenu = $this->getNavMenu(); return $header; }
/** * @expectedException \InvalidArgumentException */ public function testQueryMustBeValid() { $uri = new Uri(''); $uri->withQuery(new \stdClass()); }
public function testDeletePatch() { $queryParams = ['test_query_key' => 'test_query_value']; $url = new Uri('/test1/test2'); $queryStr = http_build_query($queryParams); $url->withQuery($queryStr); $reqHeaders = ['Content-Type' => 'application/json', 'X-Test-Header' => 'test_header_value']; $reqOpts = ['headers' => $reqHeaders, 'query' => $queryParams]; $expRespData = ['value' => true]; $expResp = new Response(200, ['Content-Type' => 'application/json'], json_encode($expRespData)); $httpClient = $this->getMockHttpClient(); $httpClient->expects($this->once())->method('request')->with($this->equalTo('DELETE'), $this->equalTo($url->getPath()), $this->equalTo($reqOpts))->will($this->returnValue($expResp)); $client = new Client(); $client->setHttpClient($httpClient); $data = $client->delete($url->getPath(), $queryParams, $reqHeaders); $this->assertSame($expRespData, $data); $this->assertSame($expResp, $client->getResponse()); }