當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Message\RequestInterface類代碼示例

本文整理匯總了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();
 }
開發者ID:mtobbias,項目名稱:GuaranaOS,代碼行數:58,代碼來源:PeerHttpServer.class.php

示例2: setHeaders

 /**
  * @param RequestInterface $request
  *
  * @return RequestInterface
  */
 private function setHeaders(RequestInterface $request)
 {
     foreach ($this->headers as $name => $value) {
         $request->setHeader($name, $value);
     }
     return $request;
 }
開發者ID:erliz,項目名稱:jira-api-client-guzzle-provider,代碼行數:12,代碼來源:Client.php

示例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;
 }
開發者ID:Frinstio,項目名稱:AlfredWorkflow.com,代碼行數:29,代碼來源:DefaultCacheKeyProvider.php

示例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);
 }
開發者ID:loulancn,項目名稱:core,代碼行數:7,代碼來源:AwsQueryVisitor.php

示例5: addQueryString

 private function addQueryString(array $queryString, RequestInterface $request)
 {
     ksort($queryString);
     foreach ($queryString as $key => $value) {
         $request->getQuery()->set($key, $value);
     }
 }
開發者ID:CHANDRA-BHUSHAN-SAH,項目名稱:stormpath-sdk-php,代碼行數:7,代碼來源:HttpClientRequestExecutor.php

示例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);
}
}
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:25,代碼來源:XmlVisitor.php

示例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);
     }
 }
開發者ID:owlycode,項目名稱:reactboard,代碼行數:34,代碼來源:RachetRouter.php

示例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;
 }
開發者ID:atlir,項目名稱:intercom-php,代碼行數:32,代碼來源:IntercomException.php

示例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);
 }
開發者ID:sonijoy,項目名稱:my_repo,代碼行數:10,代碼來源:S3SignatureV4.php

示例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);
 }
開發者ID:im286er,項目名稱:ent,代碼行數:10,代碼來源:S3SignatureV4.php

示例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;
 }
開發者ID:scup,項目名稱:intercom-php,代碼行數:42,代碼來源:IntercomException.php

示例12: visit

 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, $key, $value)
 {
     if ($value instanceof PostFileInterface) {
         $request->addPostFile($value);
     } else {
         $request->addPostFile($key, $value);
     }
 }
開發者ID:jsnshrmn,項目名稱:Suma,代碼行數:11,代碼來源:PostFileVisitor.php

示例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();
 }
開發者ID:codesleeve,項目名稱:guard-live-reload,代碼行數:8,代碼來源:HttpFileProtocol.php

示例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;
 }
開發者ID:bileto,項目名稱:omnipay-csob,代碼行數:12,代碼來源:EchoRequest.php

示例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);
     }
 }
開發者ID:xkeygmbh,項目名稱:ifresco-php,代碼行數:11,代碼來源:PostFileVisitor.php


注:本文中的Guzzle\Http\Message\RequestInterface類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。