This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Components/BrowserKit/Response.php

114 lines
2.5 KiB
PHP
Raw Normal View History

2010-04-19 13:12:42 +01:00
<?php
namespace Symfony\Components\BrowserKit;
/*
2010-04-24 00:22:16 +01:00
* This file is part of the Symfony package.
2010-04-19 13:12:42 +01:00
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Response object.
*
* @package Symfony
* @subpackage Components_BrowserKit
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class Response
{
protected $content;
protected $status;
protected $headers;
protected $cookies;
2010-04-19 13:12:42 +01:00
/**
* Constructor.
*
* @param string $content The content of the response
* @param integer $status The response status code
* @param array $headers An array of headers
* @param array $cookies An array of cookies
*/
public function __construct($content = '', $status = 200, $headers = array(), $cookies = array())
{
$this->content = $content;
$this->status = $status;
$this->headers = $headers;
$this->cookies = $cookies;
}
public function __toString()
{
$headers = '';
foreach ($this->headers as $name => $value) {
$headers .= sprintf("%s: %s\n", $name, $value);
}
foreach ($this->cookies as $name => $cookie) {
$headers .= sprintf("Set-Cookie: %s=%s\n", $name, $cookie['value']);
}
return $headers."\n".$this->content;
}
/**
* Gets the response content.
*
* @return string The response content
*/
public function getContent()
{
return $this->content;
}
2010-04-19 13:12:42 +01:00
/**
* Gets the response status code.
*
* @return integer The response status code
*/
public function getStatus()
{
return $this->status;
}
2010-04-19 13:12:42 +01:00
/**
* Gets the response headers.
*
* @return array The response headers
*/
public function getHeaders()
{
return $this->headers;
}
2010-04-19 13:12:42 +01:00
/**
* Gets a response header.
*
* @param string $header The header name
*
* @return string The header value
*/
public function getHeader($header)
2010-04-19 13:12:42 +01:00
{
foreach ($this->headers as $key => $value) {
if (str_replace('-', '_', strtolower($key)) == str_replace('-', '_', strtolower($header)))
{
return $value;
}
}
2010-04-19 13:12:42 +01:00
}
/**
* Gets the response cookies.
*
* @return array The response cookies
*/
public function getCookies()
{
return $this->cookies;
}
2010-04-19 13:12:42 +01:00
}