本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface类的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface类的具体用法?PHP RequestInterface怎么用?PHP RequestInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onOpen
public function onOpen(ConnectionInterface $from, RequestInterface $request = null)
{
echo "New HTTP connection!\n";
//Variables in URLs are not supported in Ratchet for now
//See https://github.com/cboden/Ratchet/pull/143
$requestPath = $request->getPath();
$pathParts = explode('/', preg_replace('#^/peerjs/#', '', $requestPath));
//Remove /peerjs
$action = array_pop($pathParts);
$peerToken = array_pop($pathParts);
$peerId = array_pop($pathParts);
$key = array_pop($pathParts);
$respStatus = 200;
$respHeaders = array('X-Powered-By' => \Ratchet\VERSION, 'Access-Control-Allow-Origin' => '*');
$respBody = null;
switch ($action) {
case 'id':
$respHeaders['Content-Type'] = 'text/html';
if ($peerId === null) {
do {
$peerId = substr(sha1(uniqid('', true) . mt_rand()), 0, self::PEERID_LENGTH);
} while ($this->peerServer->peerIdExists($peerId));
}
$respBody = $peerId;
break;
case 'peers':
if (self::ALLOW_DISCOVERY) {
$peers = $this->peerServer->listPeers();
$list = array();
foreach ($peers as $peer) {
$list[] = $peer['id'];
}
$respBody = $list;
} else {
$respStatus = 401;
// Access denied
}
break;
case 'offer':
case 'candidate':
case 'answer':
case 'leave':
//TODO: start streaming?
//TODO: start streaming?
default:
$respStatus = 400;
//Bad request
}
if (is_array($respBody)) {
// Encode to JSON
$respHeaders['Content-Type'] = 'application/json';
$respBody = json_encode($respBody);
}
//Send response
$response = new Response($respStatus, $respHeaders, (string) $respBody);
$from->send((string) $response);
$from->close();
}
示例2: setHeaders
/**
* @param RequestInterface $request
*
* @return RequestInterface
*/
private function setHeaders(RequestInterface $request)
{
foreach ($this->headers as $name => $value) {
$request->setHeader($name, $value);
}
return $request;
}
示例3: getCacheKey
/**
* {@inheritdoc}
*/
public function getCacheKey(RequestInterface $request)
{
// See if the key has already been calculated
$key = $request->getParams()->get(self::CACHE_KEY);
if (!$key) {
$cloned = clone $request;
$cloned->removeHeader('Cache-Control');
// Check to see how and if the key should be filtered
foreach (explode(';', $request->getParams()->get(self::CACHE_KEY_FILTER)) as $part) {
$pieces = array_map('trim', explode('=', $part));
if (isset($pieces[1])) {
foreach (array_map('trim', explode(',', $pieces[1])) as $remove) {
if ($pieces[0] == 'header') {
$cloned->removeHeader($remove);
} elseif ($pieces[0] == 'query') {
$cloned->getQuery()->remove($remove);
}
}
}
}
$raw = (string) $cloned;
$key = 'GZ' . md5($raw);
$request->getParams()->set(self::CACHE_KEY, $key)->set(self::CACHE_KEY_RAW, $raw);
}
return $key;
}
示例4: visit
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{
$this->fqname = $command->getName();
$query = array();
$this->customResolver($value, $param, $query, $param->getWireName());
$request->addPostFields($query);
}
示例5: addQueryString
private function addQueryString(array $queryString, RequestInterface $request)
{
ksort($queryString);
foreach ($queryString as $key => $value) {
$request->getQuery()->set($key, $value);
}
}
示例6: after
public function after(CommandInterface $command, RequestInterface $request)
{
$xml = null;
if (isset($this->data[$command])) {
$xml = $this->finishDocument($this->data[$command]);
unset($this->data[$command]);
} else {
$operation = $command->getOperation();
if ($operation->getData('xmlAllowEmpty')) {
$xmlWriter = $this->createRootElement($operation);
$xml = $this->finishDocument($xmlWriter);
}
}
if ($xml) {
if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
$request->setBody($xml);
}
}
示例7: 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);
}
}
示例8: factory
/**
* Simple exception factory for creating Intercom standardised exceptions
*
* @param RequestInterface $request The Request
* @param Response $response The response
* @return BadResponseException
*/
public static function factory(RequestInterface $request, Response $response)
{
if (!static::isValidIntercomError($response->json())) {
$label = 'Unsuccessful response';
$class = __CLASS__;
} elseif ($response->isClientError()) {
$label = 'Client error response';
$class = __NAMESPACE__ . '\\ClientErrorResponseException';
} elseif ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
$message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new $class($message);
$e->setResponse($response);
$e->setRequest($request);
// Sets the errors if the error response is the standard Intercom error type
if (static::isValidIntercomError($response->json())) {
$e->setErrors($response->json()['errors']);
}
return $e;
}
示例9: signRequest
/**
* Always add a x-amz-content-sha-256 for data integrity.
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
if (!$request->hasHeader('x-amz-content-sha256')) {
$request->setHeader('x-amz-content-sha256', $this->getPresignedPayload($request));
}
parent::signRequest($request, $credentials);
}
示例10: signRequest
/**
* Always add a x-amz-content-sha-256 for data integrity.
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
if ($request instanceof EntityEnclosingRequestInterface && $request->getBody() && !$request->hasHeader('x-amz-content-sha256')) {
$request->setHeader('X-Amz-Content-Sha256', $this->getPresignedPayload($request));
}
parent::signRequest($request, $credentials);
}
示例11: factory
/**
* Simple exception factory for creating Intercom standardised exceptions
*
* @param RequestInterface $request The Request
* @param Response $response The response
* @return BadResponseException
*/
public static function factory(RequestInterface $request, Response $response)
{
$response_json = $response->json();
$intercom_unavailable_error = NULL;
if (!static::isValidIntercomError($response_json)) {
if ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
$intercom_unavailable_error = 'Service Unavailable: Back-end server is at capacity';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
} elseif ($response->isClientError()) {
$label = 'Client error response';
$class = __NAMESPACE__ . '\\ClientErrorResponseException';
} elseif ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
$message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new $class($message);
$e->setResponse($response);
$e->setRequest($request);
// Sets the errors if the error response is the standard Intercom error type
if (static::isValidIntercomError($response_json)) {
$e->setErrors($response_json['errors']);
} elseif ($intercom_unavailable_error != NULL) {
$e->setErrors(array('code' => 'service_unavailable', "message" => $intercom_unavailable_error));
}
return $e;
}
示例12: visit
/**
* {@inheritdoc}
*/
public function visit(CommandInterface $command, RequestInterface $request, $key, $value)
{
if ($value instanceof PostFileInterface) {
$request->addPostFile($value);
} else {
$request->addPostFile($key, $value);
}
}
示例13: onOpen
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
$this->log('open', $conn);
$response = new Response(200, array('Content-type' => 'text/javascript', 'Content-Length' => $this->getFilesize($request->getPath())));
$response->setBody($this->getContent($request->getPath()));
$conn->send((string) $response);
$conn->close();
}
示例14: sendAndProcessResponse
/**
* @param RequestInterface $httpRequest
* @return EchoResponse
*/
private function sendAndProcessResponse(RequestInterface $httpRequest)
{
$httpResponse = $httpRequest->send();
$data = $httpResponse->json();
$response = new EchoResponse($this, $data);
$response->setVerifier($this->getVerifier());
return $response;
}
示例15: visit
/**
* {@inheritdoc}
*/
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{
if ($value instanceof PostFileInterface) {
$request->addPostFile($value);
} else {
$request->addPostFile($param->getWireName(), $value);
}
}