当前位置: 首页>>代码示例>>PHP>>正文


PHP StreamedResponse::__construct方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::__construct方法的具体用法?PHP StreamedResponse::__construct怎么用?PHP StreamedResponse::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\StreamedResponse的用法示例。


在下文中一共展示了StreamedResponse::__construct方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @param AssetInterface $asset
  * @param AssetWriter $writer
  * @param array $cachePath
  * @param array $headers
  */
 public function __construct(AssetInterface $asset, AssetWriter $writer, $cachePath, array $headers = [])
 {
     $file = $asset->getTargetPath();
     $cachePath = $cachePath . '/' . $file;
     $cached = false;
     $cacheTime = time();
     if (is_file($cachePath)) {
         $mTime = $asset->getLastModified();
         $cacheTime = filemtime($cachePath);
         if ($mTime > $cacheTime) {
             @unlink($cachePath);
             $cacheTime = $mTime;
         } else {
             $cached = true;
         }
     }
     if (!$cached) {
         $writer->writeAsset($asset);
     }
     $stream = function () use($cachePath) {
         readfile($cachePath);
     };
     $headers['Content-Length'] = filesize($cachePath);
     if (preg_match('/.+\\.([a-zA-Z0-9]+)/', $file, $matches)) {
         $ext = $matches[1];
         if (isset($this->mimeTypes[$ext])) {
             $headers['Content-Type'] = $this->mimeTypes[$ext];
         }
     }
     parent::__construct($stream, 200, $headers);
     $date = new \DateTime();
     $date->setTimestamp($cacheTime);
     $this->setLastModified($date);
 }
开发者ID:mikegibson,项目名称:sentient,代码行数:40,代码来源:AssetResponse.php

示例2: __construct

 /**
  * Constructor.
  *
  * @param array|\Traversable $rows
  * @param string             $filename
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($rows, $filename)
 {
     if (!is_array($rows) && !$rows instanceof \Traversable) {
         throw new \InvalidArgumentException('$rows should be an array or an instance of \\Traversable.');
     }
     $this->rows = $rows;
     parent::__construct(array($this, 'output'), 200, array('Content-Type' => 'text/csv', 'Content-disposition' => 'attachment; filename=' . $filename));
 }
开发者ID:issei-m,项目名称:streamed-csv-response,代码行数:16,代码来源:StreamedCsvResponse.php

示例3: __construct

 /**
  * @param FileInterface $file
  * @param array $headers
  */
 public function __construct(FileInterface $file, array $headers = [])
 {
     $stream = function () use($file) {
         readfile($file->getAbsolutePath());
     };
     $headers['Content-Length'] = $file->getSize();
     $headers['Content-Type'] = $file->getMimeType();
     parent::__construct($stream, 200, $headers);
     $mtime = $file->getUpdated();
     $this->setCache(['etag' => (string) $mtime->getTimestamp(), 'last_modified' => $mtime, 'public' => true]);
 }
开发者ID:mikegibson,项目名称:sentient,代码行数:15,代码来源:FileResponse.php

示例4: __construct

 /**
  * @param ImageInterface $image
  * @param FilterInterface $filter
  * @param FilteredImageWriter $writer
  * @param array $headers
  */
 public function __construct(ImageInterface $image, FilterInterface $filter, FilteredImageWriter $writer, array $headers = [])
 {
     $path = $writer->getFilteredImagePath($image, $filter);
     $stream = function () use($path) {
         readfile($path);
     };
     $headers['Content-Length'] = filesize($path);
     $headers['Content-Type'] = $image->getMimeType();
     parent::__construct($stream, 200, $headers);
     $this->setLastModified($image->getUpdated());
 }
开发者ID:mikegibson,项目名称:sentient,代码行数:17,代码来源:FilteredImageResponse.php

示例5: __construct

 public function __construct($title, $template, $data = [], $options = [], $headers = [])
 {
     parent::__construct();
     $this->title = $title;
     $this->template = $template;
     $this->data = $data;
     $this->options = $options;
     $this->setCallback(function () use($title, $template, $data, $options) {
         $view = new NWTemplate();
         $view->displayPage($template, $title, $data, $options);
     });
     $this->headers = new ResponseHeaderBag($headers);
 }
开发者ID:BitLucid,项目名称:ninjawars,代码行数:13,代码来源:StreamedViewResponse.php

示例6: __construct

 /**
  * @param resource $resource
  * @param int      $status
  * @param array    $headers
  */
 public function __construct($resource, $status = 200, $headers = [])
 {
     if (!is_resource($resource)) {
         throw new \InvalidArgumentException(sprintf('A resource is expected, "%s" given', gettype($resource)));
     }
     $callback = function () use($resource) {
         while (!feof($resource)) {
             $buffer = fread($resource, StreamedFileResponse::CHUNK);
             echo $buffer;
             ob_flush();
         }
         fclose($resource);
     };
     $headers['Content-Type'] = 'application/octet-stream';
     parent::__construct($callback, $status, $headers);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:21,代码来源:StreamedFileResponse.php

示例7: __construct

 /**
  * Constructor.
  *
  * @param mixed   $data    The response data or callback
  * @param int     $status  The response status code
  * @param array   $headers An array of response headers
  */
 public function __construct($data = array(), $status = 200, $headers = array())
 {
     if (!isset($headers['Content-Type'])) {
         $headers['Content-Type'] = 'text/csv';
     }
     parent::__construct(null, $status, $headers);
     $this->exporterConfig = new ExporterConfig();
     // If a callback is passed
     if (is_callable($data)) {
         $this->setCallback($data);
     } else {
         $self = $this;
         $this->setCallback(function () use($self, $data) {
             $exporter = new Exporter($self->exporterConfig);
             $exporter->export('php://output', $data);
         });
     }
     $this->streamed = false;
 }
开发者ID:jrschumacher,项目名称:symfony-component-httpfoundation-csvresponse,代码行数:26,代码来源:CsvResponse.php

示例8: __construct

 /**
  * CsvStreamedResponse constructor.
  *
  * @param string $filename
  * @param int    $status
  * @param array  $headers
  */
 public function __construct($filename = null, $status = 200, $headers = array())
 {
     parent::__construct(null, $status, $headers);
     $this->headers->set('Content-Type', 'text/csv; charset=utf-8');
     $this->headers->set('Content-Disposition', 'attachment; filename="' . ($filename ?: 'file') . '.csv"');
     $this->callback = function () {
         $handle = fopen('php://output', 'w');
         // пишем шапку
         if (isset($this->encoding) && 'UTF-8' !== strtoupper($this->encoding)) {
             mb_convert_variables($this->encoding, 'UTF-8', $this->colums);
         }
         fputcsv($handle, $this->colums, $this->delimiter, $this->enclosure);
         $fields = array_keys($this->colums);
         if ($this->iterator instanceof IterableResult) {
             // для каждой строки
             foreach ($this->iterator as $row) {
                 $dataRow = array_shift($row);
                 // если задан колбэк для обработки одной строки
                 if (isset($this->dataRowCallback)) {
                     $callback = $this->dataRowCallback;
                     $callback($dataRow);
                 }
                 // раскидываем по колонкам данные
                 $fileRow = array();
                 foreach ($fields as $field) {
                     $fileRow[] = isset($dataRow[$field]) ? $dataRow[$field] : $this->emptyCellValue;
                 }
                 if (isset($this->encoding) && 'UTF-8' !== strtoupper($this->encoding)) {
                     mb_convert_variables($this->encoding, 'UTF-8', $fileRow);
                 }
                 fputcsv($handle, $fileRow, $this->delimiter, $this->enclosure);
             }
         } else {
             throw new \RuntimeException('Unknown iterator. Set a different callback.');
         }
         fclose($handle);
     };
 }
开发者ID:vudaltsov,项目名称:raketa,代码行数:45,代码来源:CsvStreamedResponse.php

示例9: __construct

 public function __construct($filename, $callback = null, $status = 200, $headers = [])
 {
     parent::__construct($callback, $status, array_merge(['Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT', 'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT', 'Cache-Control' => 'no-store, no-cache, must-revalidate', 'Cache-Control' => 'post-check=0, pre-check=0', 'Pragma' => 'no-cache', 'Cache-Control' => 'max-age=3600, must-revalidate', 'Content-Disposition' => 'max-age=3600, must-revalidate'], $headers));
     $this->headers->set('Content-Type', 'text/csv');
     $this->headers->set('Content-Disposition', $this->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, false === preg_match('/^[\\x20-\\x7e]*$/', $filename) ? '' : preg_replace('/[^(x20-x7F)]*$/', '', $filename)));
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:6,代码来源:CSVFileResponse.php

示例10: __construct

 /**
  * @param string $filename
  * @param int    $status
  */
 public function __construct($filename, $status = 200)
 {
     parent::__construct(null, $status);
     $this->buildHeaders($filename);
 }
开发者ID:nuxia,项目名称:nuxia-plugin,代码行数:9,代码来源:StreamedFileResponse.php


注:本文中的Symfony\Component\HttpFoundation\StreamedResponse::__construct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。