all() public method

Returns the headers.
public all ( ) : array
return array An array of headers
示例#1
0
文件: Response.php 项目: rsky/symfony
 /**
  * Sends HTTP headers.
  */
 public function sendHeaders()
 {
     if (!$this->headers->has('Content-Type')) {
         $this->headers->set('Content-Type', 'text/html');
     }
     // status
     header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
     // headers
     foreach ($this->headers->all() as $name => $values) {
         foreach ($values as $value) {
             header($name . ': ' . $value);
         }
     }
 }
 /**
  * @covers Symfony\Component\HttpFoundation\HeaderBag::replace
  */
 public function testReplace()
 {
     $bag = new HeaderBag(array('foo' => 'bar'));
     $bag->replace(array('NOPE' => 'BAR'));
     $this->assertEquals(array('nope' => array('BAR')), $bag->all(), '->replace() replaces the input with the argument');
     $this->assertFalse($bag->has('foo'), '->replace() overrides previously set the input');
 }
示例#3
0
 /**
  * @return array
  */
 public function getUpdateHeaders()
 {
     // filter normal headers to contain only updateable keys
     $keys = ['etag', 'content-length', 'content-type'];
     $headers = array_diff_key($this->headers->all(), array_flip($keys));
     return array_merge($this->metadata->getHeaders(), $headers);
 }
示例#4
0
文件: Request.php 项目: n3b/symfony
    /**
     * Overrides the PHP global variables according to this request instance.
     *
     * It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE.
     * $_FILES is never override, see rfc1867
     *
     * @api
     */
    public function overrideGlobals()
    {
        $_GET = $this->query->all();
        $_POST = $this->request->all();
        $_SERVER = $this->server->all();
        $_COOKIE = $this->cookies->all();

        foreach ($this->headers->all() as $key => $value) {
            $key = strtoupper(str_replace('-', '_', $key));
            if (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
                $_SERVER[$key] = implode(', ', $value);
            } else {
                $_SERVER['HTTP_'.$key] = implode(', ', $value);
            }
        }

        $request = array('g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE);

        $requestOrder = ini_get('request_order') ?: ini_get('variable_order');
        $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';

        $_REQUEST = array();
        foreach (str_split($requestOrder) as $order) {
            $_REQUEST = array_merge($_REQUEST, $request[$order]);
        }
    }
 private function formatHeaders(HeaderBag $headerBag)
 {
     $headers = $headerBag->all();
     $content = '';
     foreach ($headers as $name => $values) {
         $name = implode('-', array_map('ucfirst', explode('-', $name)));
         foreach ($values as $value) {
             $content .= sprintf("%s %s; ", $name . ':', $value);
         }
     }
     return $content;
 }
示例#6
0
 /**
  * Overrides the PHP global variables according to this request instance.
  *
  * It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIES, and $_FILES.
  */
 public function overrideGlobals()
 {
     $_GET = $this->query->all();
     $_POST = $this->request->all();
     $_SERVER = $this->server->all();
     $_COOKIES = $this->cookies->all();
     // FIXME: populate $_FILES
     foreach ($this->headers->all() as $key => $value) {
         $_SERVER['HTTP_' . strtoupper(str_replace('-', '_', $key))] = implode(', ', $value);
     }
     // FIXME: should read variables_order and request_order
     // to know which globals to merge and in which order
     $_REQUEST = array_merge($_GET, $_POST);
 }
 function it_handles_communication_logging(CommunicationLogger $logger, CommunicationExtractor $extractor, Request $request, Response $response, HeaderBag $requestHeaders, IEvent $event)
 {
     $request->getMethod()->shouldBeCalled()->willReturn('POST');
     $request->getContent()->shouldBeCalled()->willReturn('request');
     $request->getUri()->shouldBeCalled()->willReturn('http://example.com');
     $request->headers = $requestHeaders;
     $requestHeaders->all()->shouldBeCalled()->willReturn([]);
     $next = function (Request $request) use($response) {
         return new Response();
     };
     $extractor->getRequest(Argument::type(GuzzleRequest::class))->shouldBeCalled()->willReturn(['request' => 'request']);
     $extractor->getResponse(Argument::type(GuzzleResponse::class))->shouldBeCalled()->willReturn(['response' => 'response']);
     $logger->begin('request', 'http://example.com', 'POST', '')->shouldBeCalled()->willReturn($event);
     $logger->end($event, 'response')->shouldBeCalled();
     $this->handle($request, $next);
 }
 /**
  * Return the content digest from the headers.
  * The content digest should be set by the Symfony HTTP cache before
  * this method is invoked.
  *
  * If the content digest cannot be found then a \RuntimeException
  * is thrown.
  *
  * @param HeaderBag $headers
  *
  * @throws RuntimeException
  *
  * @return string
  */
 private function getContentDigestFromHeaders(HeaderBag $headers)
 {
     if (!$headers->has($this->options['header_content_digest'])) {
         throw new \RuntimeException(sprintf('Could not find content digest header: "%s". Got headers: "%s"', $this->options['header_content_digest'], implode('", "', array_keys($headers->all()))));
     }
     return $headers->get($this->options['header_content_digest']);
 }
示例#9
0
 /**
  * @return array
  */
 public function getHeaders()
 {
     return array_merge($this->headers->all(), $this->metadata->getHeaders());
 }
示例#10
0
 /**
  * Export data to array.
  *
  * @return array
  */
 public function toArray()
 {
     return array('ip' => $this->ip, 'headers' => $this->headers->all(), 'method' => $this->method, 'uri' => $this->uri, 'data' => $this->data->all(), 'protocol' => $this->protocol, 'scheme' => $this->scheme, 'user_agent' => $this->userAgent->getUserAgentString(), 'is_browser' => $this->isBrowser());
 }
示例#11
0
 public function testCacheControlClone()
 {
     $headers = array('foo' => 'bar');
     $bag1 = new HeaderBag($headers);
     $bag2 = new HeaderBag($bag1->all());
     $this->assertEquals($bag1->all(), $bag2->all());
 }