本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface::getQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getQuery方法的具体用法?PHP RequestInterface::getQuery怎么用?PHP RequestInterface::getQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signRequest
/**
* @param RequestInterface|EntityEnclosingRequestInterface $request
* @param Credentials $credentials
*/
public function signRequest($request, $credentials)
{
$request->setHeader('X-HMB-Signature-Method', self::DEFAULT_METHOD);
$request->setHeader('X-HMB-Signature-Version', self::DEFAULT_SIGN_VERSION);
$request->setHeader('X-HMB-TimeStamp', time());
$contentMd5 = $request instanceof EntityEnclosingRequestInterface ? md5($request->getBody()) : '';
if ($contentMd5) {
$request->setHeader('Content-MD5', $contentMd5);
}
$sign = array();
$sign[] = strtoupper($request->getMethod());
$sign[] = $request->getHost();
if ($request->getHeader('Content-MD5')) {
$sign[] = $request->getHeader('Content-MD5');
}
if ($request->getHeader('Content-Type')) {
$sign[] = $request->getHeader('Content-Type');
}
$sign[] = $request->getHeader('X-HMB-Signature-Method');
$sign[] = $request->getHeader('X-HMB-Signature-Version');
$sign[] = $request->getHeader('X-HMB-TimeStamp');
if ($request->getHeader('X-HMB-User-Session-Token')) {
$sign[] = $request->getHeader('X-HMB-User-Session-Token');
}
$sign[] = $request->getQuery(true) ? $request->getPath() . '?' . $request->getQuery(true) : $request->getPath();
$signature = base64_encode(hash_hmac(strtolower($request->getHeader('X-HMB-Signature-Method')), implode("\n", $sign), $credentials->getSecret()));
$request->setHeader('Authorization', sprintf('%s %s:%s', self::AUTHORIZATION_SCHME, $credentials->getKey(), $signature));
}
示例2: addQueryString
private function addQueryString(array $queryString, RequestInterface $request)
{
ksort($queryString);
foreach ($queryString as $key => $value) {
$request->getQuery()->set($key, $value);
}
}
示例3: onOpen
/**
* {@inheritdoc}
* @throws \UnexpectedValueException If a controller is not \Ratchet\Http\HttpServerInterface
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
if (null === $request) {
throw new \UnexpectedValueException('$request can not be null');
}
$context = $this->_matcher->getContext();
$context->setMethod($request->getMethod());
$context->setHost($request->getHost());
try {
$route = $this->_matcher->match($request->getPath());
} catch (MethodNotAllowedException $nae) {
return $this->close($conn, 403);
} catch (ResourceNotFoundException $nfe) {
return $this->close($conn, 404);
}
if (is_string($route['_controller']) && class_exists($route['_controller'])) {
$route['_controller'] = new $route['_controller']();
}
if (!$route['_controller'] instanceof HttpServerInterface) {
throw new \UnexpectedValueException('All routes must implement Ratchet\\Http\\HttpServerInterface');
}
$parameters = array();
foreach ($route as $key => $value) {
if (is_string($key) && '_' !== substr($key, 0, 1)) {
$parameters[$key] = $value;
}
}
$parameters = array_merge($parameters, $request->getQuery()->getAll());
$url = Url::factory($request->getPath());
$url->setQuery($parameters);
$request->setUrl($url);
$conn->controller = $route['_controller'];
$conn->controller->onOpen($conn, $request);
}
示例4: signRequest
/**
* Sign the Pusher request
*
* @link http://pusher.com/docs/rest_api#authentication
* @param RequestInterface $request
* @param Credentials $credentials
*/
public function signRequest(RequestInterface $request, Credentials $credentials)
{
$queryParameters = array('auth_key' => $credentials->getKey(), 'auth_timestamp' => time(), 'auth_version' => self::AUTH_VERSION);
if ($request instanceof EntityEnclosingRequestInterface) {
$body = $request->getBody();
$queryParameters['body_md5'] = $body->getContentLength() ? $body->getContentMd5() : '';
}
// The signature algorithm asks that keys are all lowercased
$queryParameters = array_change_key_case($request->getQuery()->toArray()) + $queryParameters;
$queryParameters = array_filter($queryParameters);
ksort($queryParameters);
$method = strtoupper($request->getMethod());
$requestPath = $request->getPath();
$query = urldecode(http_build_query($queryParameters));
$signature = $this->signString(implode("\n", array($method, $requestPath, $query)), $credentials);
$queryParameters['auth_signature'] = $signature;
$request->getQuery()->replace($queryParameters);
}
示例5: getParamsToSign
public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
{
$params = $this->getOauthParams($timestamp, $nonce);
$params->merge($request->getQuery());
if ($this->shouldPostFieldsBeSigned($request)) {
$params->merge($request->getPostFields());
}
$params = $params->toArray();
ksort($params);
return $params;
}
示例6: onCommand
public function onCommand(RequestInterface $request)
{
$applicationName = $request->getQuery()->get('app');
$module = $request->getQuery()->get('module');
if (!$module) {
$module = 'index';
}
try {
$application = $this->applications->get($applicationName);
$this->get('event_dispatcher')->dispatch($application->getName() . '.state.activate', new InteractionEvent($request));
$this->get('event_dispatcher')->dispatch($this->currentApplication->getName() . '.state.deactivate', new InteractionEvent($request));
$this->get('server.web_socket')->switchApp($applicationName, $module);
$this->currentApplication = $application;
$this->currentModule = $module;
} catch (ApplicationNotFoundException $e) {
return $this->jsonResponse(404, 'This application does not exist.');
} catch (ApplicationInitializationException $e) {
return $this->jsonResponse(400, $e->getMessage());
}
return $this->jsonResponse(200, 'Application switched.');
}
示例7: getCount
/**
* Get the issue count from the provided request.
*
*
* @param array $request
* Guzzle request for the first page of results.
* @return number
* The total number of issues for the search paramaters of the request.
*/
public function getCount(\Guzzle\Http\Message\RequestInterface $request)
{
// Make sure page isn't set from a previous call on the same request object.
$request->getQuery()->remove('page');
$issueRowCount = 0;
while (true) {
$document = new DomCrawler\Crawler((string) $request->send()->getBody());
$issueView = $document->filter('.view-project-issue-search-project-searchapi');
$issueRowCount += $issueView->filter('table.views-table tbody tr')->reduce(function (DomCrawler\Crawler $element) {
// Drupal.org is returning rows where all cells are empty,
// which bumps up the count incorrectly.
return $element->filter('td')->first()->filter('a')->count() > 0;
})->count();
$pagerNext = $issueView->filter('.pager-next a');
if (!$pagerNext->count()) {
break;
}
preg_match('/page=(\\d+)/', $pagerNext->attr('href'), $urlMatches);
$request->getQuery()->set('page', (int) $urlMatches[1]);
}
return $issueRowCount;
}
示例8: getCanonicalizedParameterString
/**
* Get the canonicalized query/parameter string for a request
*
* @param RequestInterface $request Request used to build canonicalized string
*
* @return string
*/
public function getCanonicalizedParameterString(RequestInterface $request)
{
if ($request->getMethod() == 'POST') {
$params = $request->getPostFields()->toArray();
} else {
$params = $request->getQuery()->toArray();
}
// Don't resign a previous signature value
unset($params['Signature']);
uksort($params, 'strcmp');
$str = '';
foreach ($params as $key => $val) {
$str .= rawurlencode($key) . '=' . rawurlencode($val) . '&';
}
return substr($str, 0, -1);
}
示例9: __toString
/**
* Returns an HTML-formatted string representation of the exception.
*
* @return string
* @internal
*/
public function __toString()
{
$msg = $this->getMessage();
if (is_object($this->requestObj) && $this->requestObj instanceof \Guzzle\Http\Message\Request) {
$request = array('url' => $this->requestObj->getUrl(), 'host' => $this->requestObj->getHost(), 'headers' => $this->requestObj->getRawHeaders(), 'query' => (string) $this->requestObj->getQuery());
if ($this->requestObj instanceof \Guzzle\Http\Message\EntityEnclosingRequestInterface) {
$request_body = $this->requestObj->getBody();
$request['content-type'] = $request_body->getContentType();
$request['content-length'] = $request_body->getContentLength();
$request['body'] = $request_body->__toString();
}
$msg .= "\n\nRequest: <pre>" . htmlspecialchars(print_r($request, true)) . '</pre>';
}
if (is_object($this->responseObj) && $this->responseObj instanceof \Guzzle\Http\Message\Response) {
$response = array('status' => $this->responseObj->getStatusCode(), 'headers' => $this->responseObj->getRawHeaders(), 'body' => $this->responseBody);
$msg .= "\n\nResponse: <pre>" . htmlspecialchars(print_r($response, true)) . '</pre>';
}
return $msg;
}
示例10: getCanonicalizedQueryString
/**
* Get the canonicalized query string for a request
*
* @param RequestInterface $request
* @return string
*/
protected function getCanonicalizedQueryString(RequestInterface $request)
{
$queryParams = $request->getQuery()->getAll();
unset($queryParams['X-Amz-Signature']);
if (empty($queryParams)) {
return '';
}
$qs = '';
ksort($queryParams);
foreach ($queryParams as $key => $values) {
if (is_array($values)) {
sort($values);
} elseif (!$values) {
$values = array('');
}
foreach ((array) $values as $value) {
$qs .= rawurlencode($key) . '=' . rawurlencode($value) . '&';
}
}
return substr($qs, 0, -1);
}
示例11: getParamsToSign
public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
{
$params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $nonce, 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_version' => $this->config['version']));
// Filter out oauth_token during temp token step, as in request_token.
if ($this->config['token'] !== false) {
$params->add('oauth_token', $this->config['token']);
}
// Add call back uri
if (isset($this->config['callback_uri']) && !empty($this->config['callback_uri'])) {
$params->add('oauth_callback', $this->config['callback_uri']);
}
// Add query string parameters
$params->merge($request->getQuery());
// Add POST fields to signing string
if (!$this->config->get('disable_post_params') && $request instanceof EntityEnclosingRequestInterface && false !== strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded')) {
$params->merge($request->getPostFields());
}
// Sort params
$params = $params->getAll();
ksort($params);
return $params;
}
示例12: visit_query
protected function visit_query(RequestInterface $request, $value, $flags)
{
if (!is_array($value)) {
throw new InvalidArgumentException('query value must be an array');
}
if ($flags & self::OPTIONS_AS_DEFAULTS) {
$query = $request->getQuery();
$query->overwriteWith(array_diff_key($value, $query->toArray()));
} else {
$request->getQuery()->overwriteWith($value);
}
}
示例13: getParamsToSign
/**
* Parameters sorted and filtered in order to properly sign a request
*
* @param RequestInterface $request Request to generate a signature for
* @param integer $timestamp Timestamp to use for nonce
* @param string $nonce
*
* @return array
*/
public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
{
$params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $nonce, 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_token' => $this->config['token'], 'oauth_version' => $this->config['version']));
if (array_key_exists('callback', $this->config) == true) {
$params['oauth_callback'] = $this->config['callback'];
}
if (array_key_exists('verifier', $this->config) == true) {
$params['oauth_verifier'] = $this->config['verifier'];
}
// Add query string parameters
$params->merge($request->getQuery());
// Add POST fields to signing string if required
if ($this->shouldPostFieldsBeSigned($request)) {
$params->merge($request->getPostFields());
}
// Sort params
$params = $params->toArray();
ksort($params);
return $params;
}
示例14: visit
/**
* {@inheritdoc}
*/
public function visit(CommandInterface $command, RequestInterface $request, $key, $value)
{
$request->getQuery()->set($key, $value);
}
示例15: moveHeadersToQuery
private function moveHeadersToQuery(RequestInterface $request)
{
$query = $request->getQuery();
foreach ($request->getHeaders() as $name => $header) {
if (substr($name, 0, 5) == 'x-amz') {
$query[$header->getName()] = (string) $header;
}
if ($name !== 'host') {
$request->removeHeader($name);
}
}
}