class HtmlResponse in Zircon Profile 8
Same name in this branch
- 8 vendor/zendframework/zend-diactoros/src/Response/HtmlResponse.php \Zend\Diactoros\Response\HtmlResponse
- 8 core/lib/Drupal/Core/Render/HtmlResponse.php \Drupal\Core\Render\HtmlResponse
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-diactoros/src/Response/HtmlResponse.php \Zend\Diactoros\Response\HtmlResponse
HTML response.
Allows creating a response by passing an HTML string to the constructor; by default, sets a status code of 200 and sets the Content-Type header to text/html.
Hierarchy
- class \Zend\Diactoros\Response implements ResponseInterface uses MessageTrait
- class \Zend\Diactoros\Response\HtmlResponse uses InjectContentTypeTrait
Expanded class hierarchy of HtmlResponse
1 file declares its use of HtmlResponse
- TestControllers.php in core/
modules/ system/ tests/ modules/ router_test_directory/ src/ TestControllers.php - Contains \Drupal\router_test\TestControllers.
File
- vendor/
zendframework/ zend-diactoros/ src/ Response/ HtmlResponse.php, line 24
Namespace
Zend\Diactoros\ResponseView source
class HtmlResponse extends Response {
use InjectContentTypeTrait;
/**
* Create an HTML response.
*
* Produces an HTML response with a Content-Type of text/html and a default
* status of 200.
*
* @param string|StreamInterface $html HTML or stream for the message body.
* @param int $status Integer status code for the response; 200 by default.
* @param array $headers Array of headers to use at initialization.
* @throws InvalidArgumentException if $html is neither a string or stream.
*/
public function __construct($html, $status = 200, array $headers = []) {
parent::__construct($this
->createBody($html), $status, $this
->injectContentType('text/html', $headers));
}
/**
* Create the message body.
*
* @param string|StreamInterface $html
* @return StreamInterface
* @throws InvalidArgumentException if $html is neither a string or stream.
*/
private function createBody($html) {
if ($html instanceof StreamInterface) {
return $html;
}
if (!is_string($html)) {
throw new InvalidArgumentException(sprintf('Invalid content (%s) provided to %s', is_object($html) ? get_class($html) : gettype($html), __CLASS__));
}
$body = new Stream('php://temp', 'wb+');
$body
->write($html);
return $body;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HtmlResponse:: |
private | function | Create the message body. | |
HtmlResponse:: |
public | function |
Create an HTML response. Overrides Response:: |
|
InjectContentTypeTrait:: |
private | function | Inject the provided Content-Type, if none is already present. | |
MessageTrait:: |
protected | property | Map of normalized header name to original name used to register header. | |
MessageTrait:: |
protected | property | List of all registered headers, as key => array of values. | |
MessageTrait:: |
private | property | ||
MessageTrait:: |
private | property | ||
MessageTrait:: |
private | function | Test that an array contains only strings | |
MessageTrait:: |
private static | function | Assert that the provided header values are valid. | |
MessageTrait:: |
private | function | Filter a set of headers to ensure they are in the correct internal format. | |
MessageTrait:: |
private static | function | Test if a value is a string | |
MessageTrait:: |
public | function | Gets the body of the message. | |
MessageTrait:: |
public | function | Retrieves a message header value by the given case-insensitive name. | 1 |
MessageTrait:: |
public | function | Retrieves a comma-separated string of the values for a single header. | |
MessageTrait:: |
public | function | Retrieves all message headers. | 1 |
MessageTrait:: |
public | function | Retrieves the HTTP protocol version as a string. | |
MessageTrait:: |
public | function | Checks if a header exists by the given case-insensitive name. | |
MessageTrait:: |
public | function | Return an instance with the specified header appended with the given value. | |
MessageTrait:: |
public | function | Return an instance with the specified message body. | |
MessageTrait:: |
public | function | Return an instance with the provided header, replacing any existing values of any headers with the same case-insensitive name. | |
MessageTrait:: |
public | function | Return an instance without the specified header. | |
MessageTrait:: |
public | function | Return an instance with the specified HTTP protocol version. | |
Response:: |
private | property | Map of standard HTTP status code/reason phrases | |
Response:: |
private | property | ||
Response:: |
private | property | ||
Response:: |
private | function | Ensure header names and values are valid. | |
Response:: |
public | function |
Gets the response reason phrase associated with the status code. Overrides ResponseInterface:: |
|
Response:: |
public | function |
Gets the response status code. Overrides ResponseInterface:: |
|
Response:: |
private | function | Validate a status code. | |
Response:: |
public | function |
Return an instance with the specified status code and, optionally, reason phrase. Overrides ResponseInterface:: |