本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface::getMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getMethod方法的具体用法?PHP RequestInterface::getMethod怎么用?PHP RequestInterface::getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canCacheRequest
public function canCacheRequest(RequestInterface $request)
{
if ($request->getMethod() != RequestInterface::GET && $request->getMethod() != RequestInterface::HEAD) {
return false;
}
if ($request->hasHeader('Cache-Control') && $request->getHeader('Cache-Control')->hasDirective('no-store')) {
return false;
}
return true;
}
示例2: onOpen
/**
* {@inheritdoc}
*/
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 {
$parameters = $this->_matcher->match($request->getPath());
} catch (MethodNotAllowedException $nae) {
return $this->close($conn, 403);
} catch (ResourceNotFoundException $nfe) {
return $this->close($conn, 404);
}
if ($parameters['_controller'] instanceof ServingCapableInterface) {
$parameters['_controller']->serve($conn, $request, $parameters);
} else {
$query = array();
foreach ($query as $key => $value) {
if (is_string($key) && '_' !== substr($key, 0, 1)) {
$query[$key] = $value;
}
}
$url = Url::factory($request->getPath());
$url->setQuery($query);
$request->setUrl($url);
$conn->controller = $parameters['_controller'];
$conn->controller->onOpen($conn, $request);
}
}
示例3: 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));
}
示例4: signRequest
/**
* {@inheritdoc}
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
// Refresh the cached timestamp
$this->getTimestamp(true);
// Add default headers
$request->setHeader('x-amz-date', $this->getDateTime(DateFormat::RFC1123));
// Add the security token if one is present
if ($credentials->getSecurityToken()) {
$request->setHeader('x-amz-security-token', $credentials->getSecurityToken());
}
// Grab the path and ensure that it is absolute
$path = '/' . ltrim($request->getUrl(true)->normalizePath()->getPath(), '/');
// Begin building the string to sign
$sign = $request->getMethod() . "\n" . "{$path}\n" . $this->getCanonicalizedQueryString($request) . "\n";
// Get all of the headers that must be signed (host and x-amz-*)
$headers = $this->getHeadersToSign($request);
foreach ($headers as $key => $value) {
$sign .= $key . ':' . $value . "\n";
}
$sign .= "\n";
// Add the body of the request if a body is present
if ($request instanceof EntityEnclosingRequestInterface) {
$sign .= (string) $request->getBody();
}
// Add the string to sign to the request for debugging purposes
$request->getParams()->set('aws.string_to_sign', $sign);
$signature = base64_encode(hash_hmac('sha256', hash('sha256', $sign, true), $credentials->getSecretKey(), true));
// Add the authorization header to the request
$request->setHeader('x-amzn-authorization', sprintf('AWS3 AWSAccessKeyId=%s,Algorithm=HmacSHA256,SignedHeaders=%s,Signature=%s', $credentials->getAccessKeyId(), implode(';', array_keys($headers)), $signature));
}
示例5: invokeWrappedIfEntityEnclosed
protected function invokeWrappedIfEntityEnclosed($method, array $params = [])
{
if (!$this->wrapped instanceof EntityEnclosingRequestInterface) {
throw new BadMethodCallException(sprintf('Cannot call method "%s" on a request that does not enclose an entity.' . ' Did you expect a POST/PUT request instead of %s %s?', $method, $this->wrapped->getMethod(), $this->wrapped->getPath()));
}
return call_user_func_array([$this->wrapped, $method], $params);
}
示例6: 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;
}
}
$url = Url::factory($request->getPath());
$url->setQuery($parameters);
$request->setUrl($url);
$conn->controller = $route['_controller'];
$conn->controller->onOpen($conn, $request);
}
示例7: addDefaultContextOptions
protected function addDefaultContextOptions(RequestInterface $request)
{
$this->setContextValue('http', 'method', $request->getMethod());
$headers = $request->getHeaderLines();
if (!$request->hasHeader('Connection')) {
$headers[] = 'Connection: close';
}
$this->setContextValue('http', 'header', $headers);
$this->setContextValue('http', 'protocol_version', $request->getProtocolVersion());
$this->setContextValue('http', 'ignore_errors', true);
}
示例8: createCanonicalizedString
/**
* {@inheritdoc}
*/
public function createCanonicalizedString(RequestInterface $request, $expires = null)
{
$buffer = $request->getMethod() . "\n";
// Add the interesting headers
foreach ($this->signableHeaders as $header) {
$buffer .= (string) $request->getHeader($header) . "\n";
}
// Choose dates from left to right based on what's set
$date = $expires ?: (string) $request->getHeader('date');
$buffer .= "{$date}\n" . $this->createCanonicalizedAmzHeaders($request) . $this->createCanonicalizedResource($request);
return $buffer;
}
示例9: match
public function match(RequestInterface $request)
{
if ($request->getMethod() !== $this->method) {
return null;
}
foreach ($this->responses as $uri => $response) {
if (preg_match('~' . $uri . '~', $request->getUrl()) > 0) {
return $response;
}
}
return null;
}
示例10: verifyAll
/**
* Given an array of the headers this method will run through all verification methods
* @param \Guzzle\Http\Message\RequestInterface $request
* @return bool TRUE if all headers are valid, FALSE if 1 or more were invalid
*/
public function verifyAll(RequestInterface $request)
{
$passes = 0;
$passes += (int) $this->verifyMethod($request->getMethod());
$passes += (int) $this->verifyHTTPVersion($request->getProtocolVersion());
$passes += (int) $this->verifyRequestURI($request->getPath());
$passes += (int) $this->verifyHost((string) $request->getHeader('Host'));
$passes += (int) $this->verifyUpgradeRequest((string) $request->getHeader('Upgrade'));
$passes += (int) $this->verifyConnection((string) $request->getHeader('Connection'));
$passes += (int) $this->verifyKey((string) $request->getHeader('Sec-WebSocket-Key'));
//$passes += (int)$this->verifyVersion($headers['Sec-WebSocket-Version']); // Temporarily breaking functionality
return 7 === $passes;
}
示例11: shouldRevalidate
public function shouldRevalidate(RequestInterface $request, Response $response)
{
if ($request->getMethod() != RequestInterface::GET) {
return false;
}
$reqCache = $request->getHeader('Cache-Control');
$resCache = $response->getHeader('Cache-Control');
$revalidate = $request->getHeader('Pragma') == 'no-cache' || $reqCache && ($reqCache->hasDirective('no-cache') || $reqCache->hasDirective('must-revalidate')) || $resCache && ($resCache->hasDirective('no-cache') || $resCache->hasDirective('must-revalidate'));
if (!$revalidate && !$resCache && $response->hasHeader('ETag')) {
$revalidate = true;
}
return $revalidate;
}
示例12: 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);
}
示例13: 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);
}
示例14: 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');
}
$conn->controller = $route['_controller'];
$conn->controller->onOpen($conn, $request);
}
示例15: canResponseSatisfyRequest
/**
* Check if a cache response satisfies a request's caching constraints
*
* @param RequestInterface $request Request to validate
* @param Response $response Response to validate
*
* @return bool
*/
public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
{
$responseAge = $response->getAge();
// Check the request's max-age header against the age of the response
if ($request->hasCacheControlDirective('max-age') && $responseAge > $request->getCacheControlDirective('max-age')) {
return false;
}
// Check the response's max-age header
if ($response->isFresh() === false) {
$maxStale = $request->getCacheControlDirective('max-stale');
if (null !== $maxStale) {
if ($maxStale !== true && $response->getFreshness() < -1 * $maxStale) {
return false;
}
} elseif ($response->hasCacheControlDirective('max-age') && $responseAge > $response->getCacheControlDirective('max-age')) {
return false;
}
}
// Only revalidate GET requests
if ($request->getMethod() == RequestInterface::GET) {
// Check if the response must be validated against the origin server
if ($request->getHeader('Pragma') == 'no-cache' || $request->hasCacheControlDirective('no-cache') || $request->hasCacheControlDirective('must-revalidate') || $response->hasCacheControlDirective('must-revalidate') || $response->hasCacheControlDirective('no-cache')) {
// no-cache: When no parameters are present, always revalidate
// When parameters are present in no-cache and the request includes those same parameters, then the
// response must re-validate. I'll need an example of what fields look like in order to implement a
// smarter version of no-cache
// Requests can decline to revalidate against the origin server by setting the cache.revalidate param:
// - never - To never revalidate and always contact the origin server
// - skip - To skip revalidation and just use what is in cache
switch ($request->getParams()->get('cache.revalidate')) {
case 'never':
return false;
case 'skip':
return true;
default:
return $this->revalidation->revalidate($request, $response);
}
}
}
return true;
}