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


PHP ResponseInterface::withAddedHeader方法代码示例

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


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

示例1: setHeadersFromArray

 /**
  * Add headers represented by an array of header lines.
  *
  * @param string[] $headers Response headers as array of header lines.
  *
  * @return $this
  *
  * @throws \UnexpectedValueException For invalid header values.
  * @throws \InvalidArgumentException For invalid status code arguments.
  */
 public function setHeadersFromArray(array $headers)
 {
     $statusLine = trim(array_shift($headers));
     $parts = explode(' ', $statusLine, 3);
     if (count($parts) < 2 || substr(strtolower($parts[0]), 0, 5) !== 'http/') {
         throw new \UnexpectedValueException(sprintf('"%s" is not a valid HTTP status line', $statusLine));
     }
     $reasonPhrase = count($parts) > 2 ? $parts[2] : '';
     $this->response = $this->response->withStatus((int) $parts[1], $reasonPhrase)->withProtocolVersion(substr($parts[0], 5));
     foreach ($headers as $headerLine) {
         $headerLine = trim($headerLine);
         if ('' === $headerLine) {
             continue;
         }
         $parts = explode(':', $headerLine, 2);
         if (count($parts) !== 2) {
             throw new \UnexpectedValueException(sprintf('"%s" is not a valid HTTP header line', $headerLine));
         }
         $name = trim(urldecode($parts[0]));
         $value = trim(urldecode($parts[1]));
         if ($this->response->hasHeader($name)) {
             $this->response = $this->response->withAddedHeader($name, $value);
         } else {
             $this->response = $this->response->withHeader($name, $value);
         }
     }
     return $this;
 }
开发者ID:Nyholm,项目名称:message,代码行数:38,代码来源:ResponseBuilder.php

示例2: options

 /**
  * Options
  *
  * Responding to OPTIONS requests and checks for implemented
  * methods that matches HTTP METHODS.
  *
  * @return array
  * @throws MethodNotAllowed
  */
 public function options()
 {
     if (!$this->response instanceof ResponseInterface) {
         throw new MethodNotAllowed();
     }
     // Get all implemented methods for this resources
     $methods = get_class_methods(get_class($this));
     // Get supported verbs
     $validMethods = $this->container['validHttpVerbs'];
     // Loop though class functions/methods
     foreach ($methods as $key => &$method) {
         $method = strtoupper($method);
         // If class function/method isn't a verb, then unset it
         if (!in_array($method, $validMethods)) {
             unset($methods[$key]);
         }
     }
     // Set accept header
     $this->response = $this->response->withAddedHeader('Allow', implode(', ', $methods));
     // Prepare output
     $output = [];
     $output['Content-Type'] = $this->container['contentTypes'];
     $output['Accept'] = $this->container['acceptTypes'];
     foreach ($methods as $verb) {
         $doc = $this->parseMethodDoc($verb);
         // Check if there is any output to show
         if (!empty($doc)) {
             $output['methods'][$verb] = $doc;
         }
     }
     // return output
     return $output;
 }
开发者ID:phapi,项目名称:endpoint,代码行数:42,代码来源:Endpoint.php

示例3: withAddedHeader

 /**
  * Proxy to PsrResponseInterface::withAddedHeader()
  *
  * {@inheritdoc}
  */
 public function withAddedHeader($header, $value)
 {
     if ($this->complete) {
         return $this;
     }
     $new = $this->psrResponse->withAddedHeader($header, $value);
     return new self($new);
 }
开发者ID:fabiocarneiro,项目名称:zend-stratigility,代码行数:13,代码来源:Response.php

示例4: addToResponse

 /**
  * Add the set cookies to a response.
  *
  * @param ResponseInterface $response
  *
  * @return ResponseInterface
  */
 public function addToResponse(ResponseInterface $response) : ResponseInterface
 {
     $header = [];
     foreach ($this->cookies as $setCookie) {
         $header[] = $setCookie->toHeaderValue();
     }
     return $response->withAddedHeader('Set-Cookie', $header);
 }
开发者ID:hansott,项目名称:psr7-cookies,代码行数:15,代码来源:ResponseCookies.php

示例5: withAddedHeader

 /**
  * Proxy to PsrResponseInterface::withAddedHeader()
  *
  * {@inheritdoc}
  * @throws RuntimeException if response is already completed
  */
 public function withAddedHeader($header, $value)
 {
     if ($this->complete) {
         throw $this->responseIsAlreadyCompleted(__METHOD__);
     }
     $new = $this->psrResponse->withAddedHeader($header, $value);
     return new self($new);
 }
开发者ID:michaelmoussa,项目名称:zend-stratigility,代码行数:14,代码来源:Response.php

示例6: createRequestHeaders

 /**
  * Create all headers for a regular request
  */
 protected function createRequestHeaders()
 {
     $headers = [];
     // Set Allowed origin header (either * or Origin from request)
     $headers = $this->createOriginHeader($headers);
     // Set support credentials header
     $headers = $this->createCredentialsHeader($headers);
     // Set exposed headers header
     $headers = $this->createExposedHeadersHeader($headers);
     // Add the headers to the response
     foreach ($headers as $name => $value) {
         $this->response = $this->response->withAddedHeader($name, (string) $value);
     }
 }
开发者ID:phapi,项目名称:middleware-cors,代码行数:17,代码来源:Cors.php

示例7: addHeader

 /**
  * Add header represented by a string.
  *
  * @param string $headerLine Response header as a string.
  *
  * @return $this
  *
  * @throws \InvalidArgumentException For invalid header names or values.
  */
 public function addHeader($headerLine)
 {
     $parts = explode(':', $headerLine, 2);
     if (count($parts) !== 2) {
         throw new \InvalidArgumentException(sprintf('"%s" is not a valid HTTP header line', $headerLine));
     }
     $name = trim(urldecode($parts[0]));
     $value = trim(urldecode($parts[1]));
     if ($this->response->hasHeader($name)) {
         $this->response = $this->response->withAddedHeader($name, $value);
     } else {
         $this->response = $this->response->withHeader($name, $value);
     }
     return $this;
 }
开发者ID:mekras,项目名称:message,代码行数:24,代码来源:ResponseBuilder.php

示例8: __invoke

 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $index = $this->storage->getIndex();
     return $response->withAddedHeader('X-Demeter-Index', $index);
 }
开发者ID:mt-olympus,项目名称:demeter,代码行数:5,代码来源:SetHeader.php

示例9: withAddedHeader

 /**
  * {@inheritdoc}
  */
 public function withAddedHeader($name, $value)
 {
     return new HttpException($this->response->withAddedHeader($name, $value), $this->attributes);
 }
开发者ID:wandu,项目名称:http,代码行数:7,代码来源:HttpException.php

示例10: addToResponse

 public function addToResponse(ResponseInterface $response) : ResponseInterface
 {
     return $response->withAddedHeader('Set-Cookie', $this->toHeaderValue());
 }
开发者ID:hansott,项目名称:psr7-cookies,代码行数:4,代码来源:SetCookie.php

示例11: respondWithSessionCookie

 /**
  * Add session cookie Set-Cookie header to response.
  *
  * @param ResponseInterface $response
  *
  * @throws \InvalidArgumentException
  *
  * @return ResponseInterface
  */
 protected function respondWithSessionCookie(ResponseInterface $response)
 {
     if (session_status() !== PHP_SESSION_ACTIVE || !array_key_exists($this->sessionTimeoutKey, $_SESSION)) {
         $expireTime = time() - $this->sessionLifetime;
     } else {
         $expireTime = $_SESSION[$this->sessionTimeoutKey];
     }
     $cookieParams = [sprintf('expires=%s; max-age=%s', gmdate('D, d M Y H:i:s T', $expireTime), $this->sessionLifetime)];
     if (trim($this->getSessionSetting('cookie_path')) !== '') {
         $cookieParams[] = 'path=' . $this->getSessionSetting('cookie_path');
     }
     if (trim($this->getSessionSetting('cookie_domain')) !== '') {
         $cookieParams[] = 'domain=' . $this->getSessionSetting('cookie_domain');
     }
     if ((bool) $this->getSessionSetting('cookie_secure')) {
         $cookieParams[] = 'secure';
     }
     if ((bool) $this->getSessionSetting('cookie_httponly')) {
         $cookieParams[] = 'httponly';
     }
     return $response->withAddedHeader('Set-Cookie', sprintf('%s=%s; %s', urlencode($this->sessionName), urlencode(session_id()), implode('; ', $cookieParams)));
 }
开发者ID:juliangut,项目名称:sessionware,代码行数:31,代码来源:SessionWare.php

示例12: apply

 public function apply(ResponseInterface $respose)
 {
     return $respose->withAddedHeader(self::HEADER_NAME, (string) $this);
 }
开发者ID:zuhdil,项目名称:set-cookie,代码行数:4,代码来源:SetCookie.php

示例13: removeToken

 /**
  * {@inheritdoc}
  */
 public function removeToken(Request $request, Response $response, TokenInterface $token)
 {
     return $response->withAddedHeader('Set-Cookie', $this->cookieHeader($request, null));
 }
开发者ID:spiral-modules,项目名称:auth,代码行数:7,代码来源:CookieTokenOperator.php

示例14: mountToken

 /**
  * {@inheritdoc}
  */
 public function mountToken(Request $request, Response $response, TokenInterface $token)
 {
     return $response->withAddedHeader($this->header, $token->getHash());
 }
开发者ID:spiral-modules,项目名称:auth,代码行数:7,代码来源:HeaderTokenOperator.php

示例15: withAddedHeader

 /**
  * {@inheritDoc}
  */
 public function withAddedHeader($name, $value)
 {
     return new self($this->app, $this->decorated->withAddedHeader($name, $value));
 }
开发者ID:ezimuel,项目名称:tonis,代码行数:7,代码来源:Response.php


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