当前位置: 首页>>代码示例>>PHP>>正文


PHP Message\ResponseInterface类代码示例

本文整理汇总了PHP中Psr\Http\Message\ResponseInterface的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface类的具体用法?PHP ResponseInterface怎么用?PHP ResponseInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ResponseInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkResponseStatusCode

 /**
  * Check the response status code.
  *
  * @param ResponseInterface $response
  * @param int $expectedStatusCode
  *
  * @throws \RuntimeException on unexpected status code
  */
 private function checkResponseStatusCode(ResponseInterface $response, $expectedStatusCode)
 {
     $statusCode = $response->getStatusCode();
     if ($statusCode !== $expectedStatusCode) {
         throw new \RuntimeException('Wunderlist API returned status code ' . $statusCode . ' expected ' . $expectedStatusCode);
     }
 }
开发者ID:e-tipalchuk,项目名称:wunderlist-api-demo,代码行数:15,代码来源:WunderlistClient.php

示例2: mainAction

 /**
  * @param ServerRequestInterface $request the current request
  * @param ResponseInterface $response
  * @return ResponseInterface the response with the content
  */
 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
 {
     $this->initPage();
     $this->main();
     $response->getBody()->write($this->content);
     return $response;
 }
开发者ID:vip3out,项目名称:TYPO3.CMS,代码行数:12,代码来源:FileSystemNavigationFrameController.php

示例3: checkResponse

 /**
  * Checks Fitbit API response for errors.
  *
  * @throws IdentityProviderException
  * @param  ResponseInterface $response
  * @param  array|string $data Parsed response data
  * @return void
  */
 protected function checkResponse(ResponseInterface $response, $data)
 {
     if (!empty($data['errors'][0])) {
         $message = $data['errors'][0]['errorType'] . ': ' . $data['errors'][0]['message'];
         throw new IdentityProviderException($message, $response->getStatusCode(), $data);
     }
 }
开发者ID:stevenmaguire,项目名称:oauth2-fitbit,代码行数:15,代码来源:Fitbit.php

示例4: __invoke

 /**
  * Invoke error handler
  *
  * @param  ServerRequestInterface $request  The most recent Request object
  * @param  ResponseInterface      $response The most recent Response object
  * @param  string[]               $methods  Allowed HTTP methods
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $methods)
 {
     if ($request->getMethod() === 'OPTIONS') {
         $status = 200;
         $contentType = 'text/plain';
         $output = $this->renderPlainNotAllowedMessage($methods);
     } else {
         $status = 405;
         $contentType = $this->determineContentType($request);
         switch ($contentType) {
             case 'application/json':
                 $output = $this->renderJsonNotAllowedMessage($methods);
                 break;
             case 'text/xml':
             case 'application/xml':
                 $output = $this->renderXmlNotAllowedMessage($methods);
                 break;
             case 'text/html':
                 $output = $this->renderHtmlNotAllowedMessage($methods);
                 break;
         }
     }
     $body = new Body(fopen('php://temp', 'r+'));
     $body->write($output);
     $allow = implode(', ', $methods);
     return $response->withStatus($status)->withHeader('Content-type', $contentType)->withHeader('Allow', $allow)->withBody($body);
 }
开发者ID:psedge,项目名称:beerpong,代码行数:36,代码来源:NotAllowed.php

示例5: payload

 protected function payload(ResponseInterface $response, StructureShape $member, array &$result)
 {
     $jsonBody = $this->parseJson($response->getBody());
     if ($jsonBody) {
         $result += $this->parser->parse($member, $jsonBody);
     }
 }
开发者ID:abdala,项目名称:generic-api-client,代码行数:7,代码来源:RestJsonParser.php

示例6: validateBody

 /**
  * @param \Psr\Http\Message\ResponseInterface $response
  * @throws \Exception
  */
 public function validateBody(ResponseInterface $response)
 {
     $errors = $this->validateMessage(json_decode($response->getBody()));
     if (empty($errors) === false) {
         $this->exceptionFactory->createResponseBodyInvalidJsonApiException($response, $errors, $this->includeOriginalMessage);
     }
 }
开发者ID:garethwi,项目名称:yin,代码行数:11,代码来源:ResponseValidator.php

示例7: getNotFoundResponse

 protected function getNotFoundResponse(RequestInterface $request, ResponseInterface $response, \Exception $exception)
 {
     $output = json_encode(['error_message' => $exception->getMessage()], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     $body = new Body(fopen('php://temp', 'r+'));
     $body->write($output);
     return $response->withStatus(404)->withHeader('Content-type', 'application/json')->withBody($body);
 }
开发者ID:EugeneKirillov,项目名称:organization-relationships,代码行数:7,代码来源:Error.php

示例8: create

 /**
  * Return a new exception depending on the HTTP status code
  *
  * @param ResponseInterface $response Server-side response
  * @return ActionAlreadyDoneException|BadRequestException|BadTokenException|PermissionDeniedException|RealDebridException|UnknownResourceException
  */
 public static function create(ResponseInterface $response)
 {
     $error = json_decode($response->getBody());
     switch ($response->getStatusCode()) {
         case 202:
             return new ActionAlreadyDoneException();
             break;
             /*case 400:
               return new BadRequestException();
               break;*/
         /*case 400:
           return new BadRequestException();
           break;*/
         case 401:
             return new BadTokenException();
             break;
         case 403:
             return new PermissionDeniedException();
             break;
         case 404:
             return new UnknownResourceException();
             break;
         case 503:
             return new FileUnavailableException();
             break;
     }
     return new RealDebridException($error);
 }
开发者ID:ValentinGot,项目名称:real-debrid,代码行数:34,代码来源:ExceptionStatusCodeFactory.php

示例9: checkResponse

 protected function checkResponse(ResponseInterface $response, $data)
 {
     if ($response->getStatusCode() >= 400) {
         $msg = $data['error_description'] ?: (string) $response->getReasonPhrase();
         throw new IdentityProviderException($msg, $response->getStatusCode(), $response);
     }
 }
开发者ID:adam-paterson,项目名称:oauth2-rdio,代码行数:7,代码来源:Rdio.php

示例10: httpError

 /**
  * Helper method responsible for constructing and returning {@see BadResponseError} exceptions.
  *
  * @param RequestInterface  $request  The faulty request
  * @param ResponseInterface $response The error-filled response
  *
  * @return BadResponseError
  */
 public function httpError(RequestInterface $request, ResponseInterface $response)
 {
     $message = $this->header('HTTP Error');
     $message .= sprintf("The remote server returned a \"%d %s\" error for the following transaction:\n\n", $response->getStatusCode(), $response->getReasonPhrase());
     $message .= $this->header('Request');
     $message .= trim(str($request)) . PHP_EOL . PHP_EOL;
     $message .= $this->header('Response');
     $message .= trim(str($response)) . PHP_EOL . PHP_EOL;
     $message .= $this->header('Further information');
     // @codeCoverageIgnoreStart
     switch ($response->getStatusCode()) {
         case 400:
             $message .= "Please ensure that your input values are valid and well-formed. ";
             break;
         case 401:
             $message .= "Please ensure that your authentication credentials are valid. ";
             break;
         case 404:
             $message .= "Please ensure that the resource you're trying to access actually exists. ";
             break;
         case 500:
             $message .= "Please try this operation again once you know the remote server is operational. ";
             break;
     }
     // @codeCoverageIgnoreEnd
     $message .= "Visit http://docs.php-opencloud.com/en/latest/http-codes for more information about debugging " . "HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues.";
     $e = new BadResponseError($message);
     $e->setRequest($request);
     $e->setResponse($response);
     return $e;
 }
开发者ID:alewitt,项目名称:openstack,代码行数:39,代码来源:Builder.php

示例11: getStatusCode

 /**
  * Get status code of response.
  *
  * @return int
  * @throws ComicApiException
  */
 public function getStatusCode()
 {
     if ($this->response instanceof ResponseInterface) {
         return $this->response->getStatusCode();
     }
     throw new ComicApiException("You can't get response without making request.");
 }
开发者ID:grz-gajda,项目名称:comic-api,代码行数:13,代码来源:GuzzleConnection.php

示例12: modify

 public function modify(ResponseInterface $response) : ResponseInterface
 {
     if (false === strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
         return $response;
     }
     return $response->withHeader('Content-Type', $this->contentType);
 }
开发者ID:ThrusterIO,项目名称:http-modifiers,代码行数:7,代码来源:VendorSpecificJsonHeaderModifier.php

示例13: handleError

 private function handleError(ServerRequestInterface $request, ResponseInterface $response, Exception $exception)
 {
     $output = $this->renderJsonErrorMessage($exception);
     $body = new Body(fopen('php://temp', 'r+'));
     $body->write($output);
     return $response->withStatus(500)->withHeader('Content-type', 'application/json')->withBody($body);
 }
开发者ID:aodkrisda,项目名称:notes-api,代码行数:7,代码来源:Error.php

示例14: checkResponse

 /**
  * Check a provider response for errors.
  *
  * @throws IdentityProviderException
  * @param  ResponseInterface $response
  * @param  string $data Parsed response data
  * @return void
  */
 protected function checkResponse(ResponseInterface $response, $data)
 {
     $statusCode = $response->getStatusCode();
     if ($statusCode >= 400) {
         throw new IdentityProviderException(isset($data['meta']['errorDetail']) ? $data['meta']['errorDetail'] : $response->getReasonPhrase(), $statusCode, $response);
     }
 }
开发者ID:stevenmaguire,项目名称:oauth2-foursquare,代码行数:15,代码来源:Foursquare.php

示例15: fileAction

 /**
  * Returns the JS file content
  *
  * @param ContainerInterface $container Dependency injection container
  * @param ServerRequestInterface $request Request object
  * @param ResponseInterface $response Response object
  * @param array $args Associative list of route parameters
  * @return ResponseInterface $response Modified response object with generated output
  */
 public static function fileAction(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args)
 {
     $contents = '';
     $files = array();
     $aimeos = $container->get('aimeos');
     $type = isset($args['type']) ? $args['type'] : 'js';
     foreach ($aimeos->getCustomPaths('admin/jqadm') as $base => $paths) {
         foreach ($paths as $path) {
             $jsbAbsPath = $base . '/' . $path;
             $jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($jsbAbsPath));
             $files = array_merge($files, $jsb2->getFiles($type));
         }
     }
     foreach ($files as $file) {
         if (($content = file_get_contents($file)) !== false) {
             $contents .= $content;
         }
     }
     $response->getBody()->write($contents);
     if ($type === 'js') {
         $response = $response->withHeader('Content-Type', 'application/javascript');
     } elseif ($type === 'css') {
         $response = $response->withHeader('Content-Type', 'text/css');
     }
     return $response;
 }
开发者ID:aimeos,项目名称:aimeos-slim,代码行数:35,代码来源:Jqadm.php


注:本文中的Psr\Http\Message\ResponseInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。