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


PHP Response::headers方法代码示例

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


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

示例1: __invoke

 /**
  * Encode data as JSON and set response header
  *
  * @param  mixed $data
  * @param  array $jsonOptions Options to pass to JsonFormatter::encode()
  * @return string|void
  */
 public function __invoke($data, array $jsonOptions = array())
 {
     $data = JsonFormatter::encode($data, null, $jsonOptions);
     if ($this->response instanceof Response) {
         $headers = $this->response->headers();
         $headers->addHeaderLine('Content-Type', 'application/json');
     }
     return $data;
 }
开发者ID:navtis,项目名称:xerxes-pazpar2,代码行数:16,代码来源:Json.php

示例2: getXmlAction

 public function getXmlAction($isin)
 {
     $display = new DisplayHelper();
     $certificate = $this->certificateRepository->load($isin);
     if (empty($certificate)) {
         return $this->response->setStatusCode(404);
     }
     try {
         $xml = $display->displayAsXml($certificate);
     } catch (\RuntimeException $e) {
         return $this->response->setStatusCode(405)->setContent($e->getMessage());
     }
     $this->response->headers()->addHeaderLine('Content-type', 'application/xml');
     return $this->response->setContent($xml);
 }
开发者ID:nfx,项目名称:zf2-casestudy,代码行数:15,代码来源:CertificateController.php

示例3: _challengeClient

    /**
     * Challenge Client
     *
     * Sets a 401 or 407 Unauthorized response code, and creates the
     * appropriate Authenticate header(s) to prompt for credentials.
     *
     * @return Zend\Authentication\Result Always returns a non-identity Auth result
     */
    protected function _challengeClient()
    {
        if ($this->_imaProxy) {
            $statusCode = 407;
            $headerName = 'Proxy-Authenticate';
        } else {
            $statusCode = 401;
            $headerName = 'WWW-Authenticate';
        }

        $this->_response->setStatusCode($statusCode);

        // Send a challenge in each acceptable authentication scheme
        $headers = $this->_response->headers();
        if (in_array('basic', $this->_acceptSchemes)) {
            $headers->addHeaderLine($headerName, $this->_basicHeader());
        }
        if (in_array('digest', $this->_acceptSchemes)) {
            $headers->addHeaderLine($headerName, $this->_digestHeader());
        }
        return new Authentication\Result(
            Authentication\Result::FAILURE_CREDENTIAL_INVALID,
            array(),
            array('Invalid or absent credentials; challenging client')
        );
    }
开发者ID:rickogden,项目名称:zf2,代码行数:34,代码来源:Http.php

示例4: testRequestCanSetHeaders

 public function testRequestCanSetHeaders()
 {
     $response = new Response();
     $headers = new \Zend\Http\Headers();
     $ret = $response->setHeaders($headers);
     $this->assertInstanceOf('Zend\\Http\\Response', $ret);
     $this->assertSame($headers, $response->headers());
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:8,代码来源:ResponseTest.php

示例5: __invoke

 /**
  * Encode data as JSON, disable layouts, and set response header
  *
  * If $keepLayouts is true, does not disable layouts.
  *
  * @param  mixed $data
  * @param  bool $keepLayouts
  * NOTE:   if boolean, establish $keepLayouts to true|false
  *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
  *         this array can contains a 'keepLayout'=>true|false
  *         that will not be passed to Zend_Json::encode method but will be used here
  * @return string|void
  */
 public function __invoke($data, $keepLayouts = false)
 {
     $options = array();
     if (is_array($keepLayouts)) {
         $options = $keepLayouts;
         $keepLayouts = array_key_exists('keepLayouts', $keepLayouts) ? $keepLayouts['keepLayouts'] : false;
         unset($options['keepLayouts']);
     }
     $data = JsonFormatter::encode($data, null, $options);
     if (!$keepLayouts && $this->layout instanceof Layout) {
         $this->layout->disableLayout();
     }
     if ($this->response instanceof Response) {
         $headers = $this->response->headers();
         $headers->addHeaderLine('Content-Type', 'application/json');
     }
     return $data;
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:31,代码来源:Json.php

示例6: redirect

 /**
  * Performs a HTTP redirection to specified URL with additional data.
  * It may generate redirected request using GET or POST HTTP method.
  * The function never returns.
  *
  * @param string $url URL to redirect to
  * @param array $params additional variable/value pairs to send
  * @param Response $response
  * @param string $method redirection method ('GET' or 'POST')
  */
 public static function redirect($url, $params = null, Response $response = null, $method = 'GET')
 {
     $url = self::absoluteUrl($url);
     $body = "";
     if (null === $response) {
         $response = new Response();
     }
     if ($method == 'POST') {
         $body = "<html><body onLoad=\"document.forms[0].submit();\">\n";
         $body .= "<form method=\"POST\" action=\"{$url}\">\n";
         if (is_array($params) && count($params) > 0) {
             foreach ($params as $key => $value) {
                 $body .= '<input type="hidden" name="' . $key . '" value="' . $value . "\">\n";
             }
         }
         $body .= "<input type=\"submit\" value=\"Continue OpenID transaction\">\n";
         $body .= "</form></body></html>\n";
     } else {
         if (is_array($params) && count($params) > 0) {
             if (strpos($url, '?') === false) {
                 $url .= '?' . self::paramsToQuery($params);
             } else {
                 $url .= '&' . self::paramsToQuery($params);
             }
         }
     }
     if (!empty($body)) {
         $response->setContent($body);
     } elseif (headers_sent()) {
         $response->setContent("<script language=\"JavaScript\"" . " type=\"text/javascript\">window.location='{$url}';" . "</script>");
     }
     $response->setStatusCode(302);
     $response->headers()->addHeaderLine('Location', $url);
     if (!headers_sent()) {
         header($response->renderStatusLine());
         foreach ($response->headers() as $header) {
             header($header->toString());
         }
     }
     echo $response->getBody();
     if (self::$exitOnRedirect) {
         exit;
     }
 }
开发者ID:rikaix,项目名称:zf2,代码行数:54,代码来源:OpenId.php

示例7: testConstructorWithHttpResponse

 public function testConstructorWithHttpResponse()
 {
     $status = 'false';
     $errorCode = 'foobar';
     $responseBody = $status . "\n" . $errorCode;
     $httpResponse = new Response();
     $httpResponse->setStatusCode(200);
     $httpResponse->headers()->addHeaderLine('Content-Type', 'text/html');
     $httpResponse->setContent($responseBody);
     $response = new ReCaptcha\Response(null, null, $httpResponse);
     $this->assertSame(false, $response->getStatus());
     $this->assertSame($errorCode, $response->getErrorCode());
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:13,代码来源:ResponseTest.php

示例8: addCookiesFromResponse

 /**
  * Parse an HTTP response, adding all the cookies set in that response
  *
  * @param Response $response
  * @param Uri\Uri|string $ref_uri Requested URI
  */
 public function addCookiesFromResponse($response, $ref_uri)
 {
     if (!$response instanceof Response) {
         throw new Exception\InvalidArgumentException('$response is expected to be a Response object');
     }
     $cookie_hdrs = $response->headers()->get('Set-Cookie');
     if (is_array($cookie_hdrs)) {
         foreach ($cookie_hdrs as $cookie) {
             $this->addCookie($cookie, $ref_uri);
         }
     } elseif (is_string($cookie_hdrs)) {
         $this->addCookie($cookie_hdrs, $ref_uri);
     }
 }
开发者ID:kingsj,项目名称:core,代码行数:20,代码来源:Cookies.php

示例9: createResponse

 protected function createResponse(ZendResponse $response)
 {
     return new Response($response->getBody(), $response->getStatusCode(), $response->headers()->toArray());
 }
开发者ID:robo47,项目名称:Goutte,代码行数:4,代码来源:Client.php


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