Response::stream PHP Метод

stream() публичный статический Метод

Return a new streamed response from the application.
public static stream ( Closure $callback, integer $status = 200, array $headers = [] ) : Symfony\Component\HttpFoundation\StreamedResponse
$callback Closure
$status integer
$headers array
Результат Symfony\Component\HttpFoundation\StreamedResponse
        public static function stream($callback, $status = 200, $headers = array())
        {
            return \Illuminate\Routing\ResponseFactory::stream($callback, $status, $headers);
        }

Usage Example

Пример #1
0
 /**
  * Exports statements as CSV.
  * @param String $id Export's ID.
  * @return StreamedResponse.
  */
 public function showCsv($id)
 {
     // should top timeouts on long queries
     set_time_limit(0);
     $opts = $this->getOptions();
     $model = $this->repo->show($id, $opts);
     return IlluminateResponse::stream(function () use($model, $opts) {
         if (ob_get_level() == 0) {
             ob_start();
         }
         // Outputs the field names (column headers).
         echo implode(',', array_map(function ($field) {
             return $field['to'];
         }, $model->fields)) . "\n";
         // Outputs the statements (rows).
         $this->repo->export($model, array_merge($opts, ['next' => function () {
             echo "\n";
             flush();
             ob_flush();
         }, 'stream' => function ($obj) {
             // Outputs the field values (column values).
             echo implode(',', array_map(function ($value) {
                 return $this->quoteCSV($value);
                 flush();
                 ob_flush();
             }, $obj));
         }]));
     }, 200, ['Content-Type' => 'text/csv']);
 }
All Usage Examples Of Response::stream