本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::__construct方法的具体用法?PHP Response::__construct怎么用?PHP Response::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param mixed $data The response data
* @param int $status The response status code
* @param array $headers An array of response headers
*/
public function __construct(array $responses = array(), $status = 200, $headers = array())
{
parent::__construct('', $status, $headers);
foreach ($responses as $response) {
$this->addResponse($response);
}
}
示例2: __construct
/**
* BlobResponse constructor.
*
* @param string $documentPath The path of the document to encode as B64
* @param int $status
* @param array $headers
*
*/
public function __construct($documentPath, $status = 200, array $headers = array())
{
$content = base64_encode(file_get_contents($documentPath));
$finfoMineType = finfo_open(FILEINFO_MIME_TYPE);
$headers['Content-Type'] = finfo_file($finfoMineType, $documentPath);
parent::__construct($content, $status, $headers);
}
示例3: __construct
/**
*
* @param string $path
* @param string $filename
* @param int $cachetime time in seconds (1 year by default)
*/
public function __construct($path, $filename = null, $cachetime = 31536000)
{
parent::__construct();
if (!is_file($path)) {
throw new FileNotFoundException($path);
}
$this->file = new SplFileInfo($path);
if (empty($filename)) {
$filename = $this->file->getBasename();
}
// last modified
$lastModified = $this->file->getMTime();
$dateLastModified = new \DateTime();
$dateLastModified->setTimestamp($lastModified);
$this->setLastModified($dateLastModified);
// etag
$etag = dechex($lastModified);
$this->setEtag($etag);
$this->setFileCacheTime($cachetime);
$mimeType = Fn::fileMimeType($filename);
// headers
$this->setContentLength($this->file->getSize());
$this->setContentType($mimeType);
$this->setContentDispositionInline($filename);
}
示例4: __construct
/**
* Constructor
*
* @param int $ttlInSeconds
* @param string $content
* @param int $status
* @param array $headers
*/
public function __construct($ttlInSeconds, $content = '', $status = 200, $headers = array())
{
$now = gmdate('D, d M Y H:i:s \\G\\M\\T', time());
$expires = gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $ttlInSeconds);
$headers = array_merge(array('Content-Type' => 'text/css', 'Pragma' => 'cache', 'Cache-Control' => 'public', 'Date' => $now, 'Last-Modified' => $now, 'Expires' => $expires), $headers);
parent::__construct($content, $status, $headers);
}
示例5: __construct
/**
* Create a simple html page, if title is given, a small skeleton is added.
* In this case you'll only have to provide the content of the body element.
* In other cases you'll have to provide the full html.
* @param string $body
* @param string $title
*/
public function __construct($body, $title = null)
{
if ($title !== null) {
$body = sprintf('<!DOCTYPE html><html><head><title>%s</title></head><body>%s</body></html>', $title, $body);
}
parent::__construct($body, 200, ['Content-Type' => 'text/html']);
}
示例6: __construct
/**
* Export Response
*
* @param array $data Data list
* @param string $fileName Name of file
* @param string $type
* @param string $encodingFrom Encode from charset
* @param string $enclosure Enclosure
* @param string $delimiter Delimiter
* @param bool $enableDownload Enable download
*/
public function __construct(array $data = NULL, $fileName = 'export', $type = self::TYPE_CSV, $encodingFrom = 'UTF-8', $enclosure = '"', $delimiter = ',', $enableDownload = true)
{
parent::__construct();
$this->setEncodingFrom($encodingFrom);
$this->setType($type);
switch ($type) {
case self::TYPE_CSV:
$this->setDelimiter($delimiter);
$this->setEnclosure($enclosure);
$this->setFileName($fileName . ".csv");
if ($data) {
$this->setCsv($data);
}
break;
case self::TYPE_XLS:
$this->setFileName($fileName . ".xls");
if ($data) {
$this->setXls($data);
}
break;
}
if ($enableDownload) {
$this->enableDownload();
}
}
示例7: __construct
/**
* Construct the basic instance properties.
*
* @param array|null $content The response content {@see setFinalContent()}
* @param int|null $status Status for this response.
* @param array $headers Headers specific to this response.
* @param array $headersGlobal The global headers configured.
* @param array $headersTypeSpecific The type-specific headers configured.
* @param string|null $charsetGlobal The global charset configured.
* @param string|null $charsetTypeSpecific The type-specific charset configured.
* @param float|null $protocolGlobal The global charset configured.
* @param float|null $protocolTypeSpecific The type-specific charset configured.
*
* @throws \InvalidArgumentException When the HTTP status code is not valid
*
* @api
*/
public function __construct($content = null, $status = null, $headers = [], $headersGlobal = [], $headersTypeSpecific = [], $charsetGlobal = null, $charsetTypeSpecific = null, $protocolGlobal = null, $protocolTypeSpecific = null)
{
parent::__construct(null, $this->getFinalStatus($status), $this->getFinalHeaders($headersGlobal, $headersTypeSpecific, $headers));
$this->setData($content);
$this->setCharset($this->getFinalCharset($charsetGlobal, $charsetTypeSpecific));
$this->setProtocolVersion($this->getFinalProtocol($protocolGlobal, $protocolTypeSpecific));
}
示例8: __construct
/**
* Construct calendar response
*
* @param Calendar $calendar Calendar
* @param int $status Response status
* @param array $headers Response headers
*/
public function __construct(Calendar $calendar, $status = 200, $headers = array())
{
$this->calendar = $calendar;
$content = utf8_encode($calendar->createCalendar());
$headers = array_merge($this->getDefaultHeaders(), $headers);
parent::__construct($content, $status, $headers);
}
示例9: __construct
/**
* Constructor.
*
* @param Template $template An object that is able to render a template with context
* @param array $context An array of context variables
* @param array $globals An array of global context variables
* @param int $status The response status code
* @param array $headers An array of response headers
*/
public function __construct(Template $template, array $context = [], array $globals = [], $status = 200, $headers = [])
{
parent::__construct(null, $status, $headers);
$this->template = $template;
$this->context = $context;
$this->addGlobals($globals);
}
示例10: __construct
public function __construct($content = '', $status = 200, $headers = array())
{
parent::__construct($content, $status, $headers);
if ($this->headers->get('Content-Type') !== 'application/xml') {
$this->headers->set('Content-Type', 'application/xml');
}
}
示例11: __construct
/**
* Constructor
*
* @param mixed $data The response data
* @param integer $status The response status code
* @param array $headers An array of response headers
*/
public function __construct($events = array(), $status = 200, $headers = array())
{
parent::__construct('', $status, $headers);
$this->headers->set('Content-Type', 'text/calendar');
$this->headers->set('Content-Disposition', 'attachment; filename=calendar.ics');
$this->setEvents($events);
}
示例12: __construct
public function __construct(TemplateEngineInterface $template = null, $view = null, $viewdata = [], $status = 200, $headers = array())
{
$this->template = $template;
$this->view = $view;
$this->viewdata = $viewdata;
parent::__construct('', $status, $headers);
}
示例13: __construct
/**
* Constructor.
*
* @param Thumbnail $thumbnail The thumbnail
* @param int $status The response status code
* @param array $headers An array of response headers
* @param bool $public Thumbnails are public by default
* @param bool $autoEtag Whether the ETag header should be automatically set
* @param bool $autoLastModified Whether the Last-Modified header should be automatically set
*/
public function __construct(Thumbnail $thumbnail, $status = 200, $headers = [], $public = true, $autoEtag = false, $autoLastModified = true)
{
parent::__construct(null, $status, $headers);
$this->setThumbnail($thumbnail, $autoEtag, $autoLastModified);
if ($public) {
$this->setPublic();
}
}
示例14: __construct
/**
* Constructor
*/
public function __construct()
{
parent::__construct(base64_decode(static::IMAGE_CONTENT));
$this->headers->set('Content-Type', static::CONTENT_TYPE);
$this->setPrivate();
$this->headers->addCacheControlDirective('no-cache', true);
$this->headers->addCacheControlDirective('must-revalidate', true);
}
示例15: __construct
public function __construct($message, $where = '', $type = '')
{
$content = new \stdClass();
$content->type = 'exception';
$content->message = $message;
$content->where = $where;
parent::__construct(json_encode($content), 500, array('Content-Type' => 'text/javascript'));
}