本文整理匯總了PHP中Illuminate\Routing\ResponseFactory::stream方法的典型用法代碼示例。如果您正苦於以下問題:PHP ResponseFactory::stream方法的具體用法?PHP ResponseFactory::stream怎麽用?PHP ResponseFactory::stream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Routing\ResponseFactory
的用法示例。
在下文中一共展示了ResponseFactory::stream方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handle
/**
* ExportAll the selected entries.
*
* @param TableBuilder $builder
* @param ResponseFactory $response
* @param array $selected
*/
public function handle(TableBuilder $builder, ResponseFactory $response, array $selected)
{
$model = $builder->getTableModel();
$stream = $builder->getTableStream();
$headers = ['Content-Disposition' => 'attachment; filename=' . $stream->getSlug() . '.csv', 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-type' => 'text/csv', 'Pragma' => 'public', 'Expires' => '0'];
$callback = function () use($selected, $model) {
$output = fopen('php://output', 'w');
/* @var EloquentModel $entry */
foreach ($model->all() as $k => $entry) {
if ($k == 0) {
fputcsv($output, array_keys($entry->toArray()));
}
fputcsv($output, $entry->toArray());
}
fclose($output);
};
$builder->setTableResponse($response->stream($callback, 200, $headers));
}
示例2: stream
/**
* Return a new streamed response from the application.
*
* @param \Closure $callback
* @param int $status
* @param array $headers
* @return \Symfony\Component\HttpFoundation\StreamedResponse
* @static
*/
public static function stream($callback, $status = 200, $headers = array())
{
return \Illuminate\Routing\ResponseFactory::stream($callback, $status, $headers);
}