__construct() public method

Constructor.
public __construct ( mixed $content = '', integer $status = 200, array $headers = [] )
$content mixed The response content, see setContent()
$status integer The response status code
$headers array An array of response headers
Ejemplo n.º 1
0
 /**
  * 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  *
  * @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);
 }
 /**
  * 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);
 }
Ejemplo n.º 5
0
 /**
  * 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']);
 }
Ejemplo n.º 6
0
 /**
  * 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();
     }
 }
Ejemplo n.º 7
0
 /**
  * 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));
 }
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * 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);
 }
Ejemplo n.º 10
0
 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');
     }
 }
 /**
  * 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);
 }
Ejemplo n.º 12
0
 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);
 }
Ejemplo n.º 13
0
 /**
  * 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();
     }
 }
 /**
  * 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);
 }
Ejemplo n.º 15
0
 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'));
 }
Ejemplo n.º 16
0
 /**
  * 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($data = null, $status = 200, $headers = array())
 {
     parent::__construct('', $status, $headers);
     if ($data == null) {
         $data = new \ArrayObject();
     }
     $this->setData($data);
 }
Ejemplo n.º 17
0
 public function __construct(Hal $hal, $status = 200, $headers = [], $prettyPrint = true)
 {
     parent::__construct(null, $status, $headers);
     $this->hal = $hal;
     $this->prettyPrint = (bool) $prettyPrint;
     $this->requestFormat = 'json';
     $this->headers->set('Content-Type', 'application/hal+json');
 }
Ejemplo n.º 18
0
 /**
  * 
  * @param \ArrayObject $aData
  * @param int $iStatus
  * @param Array $aHeaders
  * @return type
  */
 public function __construct($aData = null, $iStatus = 200, $aHeaders = array())
 {
     parent::__construct('', $iStatus, $aHeaders);
     if (null === $aData) {
         $aData = new \ArrayObject();
     }
     return $this->processData($aData);
 }
Ejemplo n.º 19
0
 /**
  * @param DataGridViewInterface $datagrid
  * @param $filename
  * @param int $status
  * @param array $headers
  * @param Translator $translator
  */
 public function __construct(DataGridViewInterface $datagrid, $filename, $status = 200, $headers = array(), Translator $translator = null)
 {
     parent::__construct('', $status, $headers);
     $this->translator = $translator;
     $this->filename = $filename;
     $this->datagrid = $datagrid;
     $this->setData();
 }
 /**
  * Constructor.
  *
  * @param mixed $content The response content, see setContent()
  * @param int $status The response status code
  * @param array $headers An array of response headers
  *
  * @param array $extra_meta
  * @api
  */
 public function __construct($content = '', $status = 200, $headers = array(), $extra_meta = array())
 {
     parent::__construct('', 200, array('Content-Type' => 'application/json'));
     $this->_content = $content;
     $this->_status = $status;
     $this->_extra_meta = $extra_meta;
     return $this->build();
 }
Ejemplo n.º 21
0
 /**
  * Constructor.
  *
  * @param \SplFileInfo|string $file               The file to stream
  * @param int                 $status             The response status code
  * @param array               $headers            An array of response headers
  * @param bool                $public             Files are public by default
  * @param null|string         $contentDisposition The type of Content-Disposition to set automatically with the filename
  * @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($file, $status = 200, $headers = array(), $public = true, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
 {
     parent::__construct(null, $status, $headers);
     $this->setFile($file, $contentDisposition, $autoEtag, $autoLastModified);
     if ($public) {
         $this->setPublic();
     }
 }
 /**
  * StreamFileResponse constructor.
  * @param File $file
  * @param int $status
  * @param array $headers
  */
 public function __construct($file, $status = 200, $headers = array())
 {
     if (!$file instanceof File) {
         throw new RuntimeException("Content must be instance of " . File::class);
     }
     parent::__construct(null, $status, $headers);
     $this->setFile($file);
 }
Ejemplo n.º 23
0
 public function __construct(array $singleResponses)
 {
     $this->singleResponses = $singleResponses;
     $this->rawContent = array();
     foreach ($this->singleResponses as $singleResponse) {
         $this->rawContent[] = $singleResponse->getRawContent();
     }
     parent::__construct(json_encode($this->rawContent), 200, array('Content-Type' => 'text/javascript'));
 }
Ejemplo n.º 24
0
 /**
  * Constructor.
  *
  * @param mixed $content The response content, see setContent()
  * @param int   $status  The response status code
  * @param array $headers An array of response headers
  *
  * @throws \InvalidArgumentException When the HTTP status code is not valid
  *
  * @api
  */
 public function __construct($content = '', $status = 200, $headers = array())
 {
     if (null !== $status) {
         $this->validateStatus($status);
     }
     list($headerNames, $headers) = $this->filterHeaders($headers);
     parent::__construct($content, $status, $headers);
     $this->headerNames = $headerNames;
 }
 public function __construct(StatsTable $statsTable, DumperInterface $dumper, $headers = array())
 {
     parent::__construct('', 200, $headers);
     $this->statsTable = $statsTable;
     $this->dumper = $dumper;
     if (!$this->headers->has(self::ST_HEADER_CONTENT_TYPE)) {
         $this->headers->set(self::ST_HEADER_CONTENT_TYPE, $dumper->getMimeType());
     }
 }
Ejemplo n.º 26
0
 public function __construct($content = '', $status = 101, $headers = array())
 {
     parent::__construct($content, $status, $headers);
     $this->headers->set('Connection', 'Upgrade');
     $this->headers->set('Upgrade', 'websocket');
     $this->headers->remove('Content-Length');
     $this->headers->remove('Cache-Control');
     $this->headers->remove('Date');
 }
 /**
  * Constructor.
  *
  * @param BinaryFile          $binaryFile         The name of the file to stream
  * @param IOServiceInterface  $ioService          The name of the file to stream
  * @param int                 $status             The response status code
  * @param array               $headers            An array of response headers
  * @param bool                $public             Files are public by default
  * @param null|string         $contentDisposition The type of Content-Disposition to set automatically with the filename
  * @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(BinaryFile $binaryFile, IOServiceInterface $ioService, $status = 200, $headers = array(), $public = true, $contentDisposition = null, $autoLastModified = true)
 {
     $this->ioService = $ioService;
     parent::__construct(null, $status, $headers);
     $this->setFile($binaryFile, $contentDisposition, $autoLastModified);
     if ($public) {
         $this->setPublic();
     }
 }
Ejemplo n.º 28
0
 /**
  * construct
  *
  * @param array     $data
  * @param message   $message
  * @param bool      $success
  * @param array     $errors
  */
 function __construct($data = array(), $success = true, $message = "", $code = "")
 {
     parent::__construct('', 200, array('Content-Type' => 'application/json'));
     $this->code = $code;
     $this->success = $success;
     $this->message = $message;
     $this->data = $data;
     $this->update();
 }
Ejemplo n.º 29
0
 /**
  * Response constructor.
  *
  * @param string $content
  * @param int    $status
  * @param array  $headers
  */
 public function __construct($content = '', $status = 200, $headers = array())
 {
     $encoders = [new XmlEncoder()];
     $normalizers = [new GetSetMethodNormalizer()];
     $serializer = new Serializer($normalizers, $encoders);
     $contents_xml = $serializer->serialize($content, 'xml');
     $headers['Content-Type'] = 'application/xml';
     parent::__construct($contents_xml, $status = 200, $headers);
 }
Ejemplo n.º 30
0
 public function __construct($result, $tid, $action, $method, $type)
 {
     $this->rawContent = new \stdClass();
     $this->rawContent->result = $result;
     $this->rawContent->tid = $tid;
     $this->rawContent->action = $action;
     $this->rawContent->method = $method;
     $this->rawContent->type = $type;
     BaseResponse::__construct('<html><body><textarea>' . json_encode($this->rawContent) . '</textarea></body></html>', 200, array('Content-Type' => 'text/html'));
 }