You are here

class Response in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/http-foundation/Response.php \Symfony\Component\HttpFoundation\Response
  2. 8 vendor/symfony/browser-kit/Response.php \Symfony\Component\BrowserKit\Response
  3. 8 vendor/zendframework/zend-diactoros/src/Response.php \Zend\Diactoros\Response
  4. 8 vendor/zendframework/zend-stdlib/src/Response.php \Zend\Stdlib\Response
  5. 8 vendor/guzzlehttp/psr7/src/Response.php \GuzzleHttp\Psr7\Response
  6. 8 vendor/jcalderonzumba/gastonjs/src/NetworkTraffic/Response.php \Zumba\GastonJS\NetworkTraffic\Response
  7. 8 vendor/symfony/psr-http-message-bridge/Tests/Fixtures/Response.php \Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\Response
Same name and namespace in other branches
  1. 8.0 vendor/symfony/browser-kit/Response.php \Symfony\Component\BrowserKit\Response

Response object.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\BrowserKit\Response

Expanded class hierarchy of Response

8 files declare their use of Response
BrowserKitDriver.php in vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php
Client.php in vendor/symfony/http-kernel/Client.php
Client.php in vendor/fabpot/goutte/Goutte/Client.php
Client.php in vendor/behat/mink-goutte-driver/src/Goutte/Client.php
ClientTest.php in vendor/symfony/browser-kit/Tests/ClientTest.php

... See full list

1 string reference to 'Response'
form_test.routing.yml in core/modules/system/tests/modules/form_test/form_test.routing.yml
core/modules/system/tests/modules/form_test/form_test.routing.yml

File

vendor/symfony/browser-kit/Response.php, line 19

Namespace

Symfony\Component\BrowserKit
View source
class Response {
  protected $content;
  protected $status;
  protected $headers;

  /**
   * Constructor.
   *
   * The headers array is a set of key/value pairs. If a header is present multiple times
   * then the value is an array of all the values.
   *
   * @param string $content The content of the response
   * @param int    $status  The response status code
   * @param array  $headers An array of headers
   */
  public function __construct($content = '', $status = 200, array $headers = array()) {
    $this->content = $content;
    $this->status = $status;
    $this->headers = $headers;
  }

  /**
   * Converts the response object to string containing all headers and the response content.
   *
   * @return string The response with headers and content
   */
  public function __toString() {
    $headers = '';
    foreach ($this->headers as $name => $value) {
      if (is_string($value)) {
        $headers .= $this
          ->buildHeader($name, $value);
      }
      else {
        foreach ($value as $headerValue) {
          $headers .= $this
            ->buildHeader($name, $headerValue);
        }
      }
    }
    return $headers . "\n" . $this->content;
  }

  /**
   * Returns the build header line.
   *
   * @param string $name  The header name
   * @param string $value The header value
   *
   * @return string The built header line
   */
  protected function buildHeader($name, $value) {
    return sprintf("%s: %s\n", $name, $value);
  }

  /**
   * Gets the response content.
   *
   * @return string The response content
   */
  public function getContent() {
    return $this->content;
  }

  /**
   * Gets the response status code.
   *
   * @return int The response status code
   */
  public function getStatus() {
    return $this->status;
  }

  /**
   * Gets the response headers.
   *
   * @return array The response headers
   */
  public function getHeaders() {
    return $this->headers;
  }

  /**
   * Gets a response header.
   *
   * @param string $header The header name
   * @param bool   $first  Whether to return the first value or all header values
   *
   * @return string|array The first header value if $first is true, an array of values otherwise
   */
  public function getHeader($header, $first = true) {
    $normalizedHeader = str_replace('-', '_', strtolower($header));
    foreach ($this->headers as $key => $value) {
      if (str_replace('-', '_', strtolower($key)) === $normalizedHeader) {
        if ($first) {
          return is_array($value) ? count($value) ? $value[0] : '' : $value;
        }
        return is_array($value) ? $value : array(
          $value,
        );
      }
    }
    return $first ? null : array();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Response::$content protected property
Response::$headers protected property
Response::$status protected property
Response::buildHeader protected function Returns the build header line.
Response::getContent public function Gets the response content.
Response::getHeader public function Gets a response header.
Response::getHeaders public function Gets the response headers.
Response::getStatus public function Gets the response status code.
Response::__construct public function Constructor.
Response::__toString public function Converts the response object to string containing all headers and the response content.