本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::create方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::create方法的具体用法?PHP StreamedResponse::create怎么用?PHP StreamedResponse::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportAction
/**
* Export all plugins
*
* @return Response Exportation file
*/
public function exportAction()
{
/**
* @var Plugin $plugin
*/
$plugin = $this->get('elcodi.manager.plugin')->getPlugin('Elcodi\\Plugin\\ProductCsvBundle');
if (!$plugin->isUsable()) {
$this->createNotFoundException($this->get('translator')->trans('product_csv_plugin.error.is_disabled'));
}
/**
* @var ProductExporter $exporter
*/
$exporter = $this->get('elcodi_plugin.product_csv.exporter');
$repository = $this->get('elcodi.repository.product');
$response = StreamedResponse::create();
$response->setCallback(function () use($repository, $exporter) {
$rows = $repository->findAll();
$exporter->export($rows);
});
$configuration = $plugin->getConfiguration();
$filename = $configuration['export_filename'];
if (empty($filename)) {
$filename = 'products.csv';
}
return $this->makeDownloadable($response, $filename, 'text/csv');
}
示例2: runLegacyScript
/**
* @param $requestPath
* @param $legacyScript
*
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
public function runLegacyScript($requestPath, $legacyScript)
{
$container = $this->container;
$prepend = $this->prependScript;
$append = $this->appendScript;
$requireLegacyScript = function () use($requestPath, $legacyScript, $container, $prepend, $append) {
$_SERVER['PHP_SELF'] = $requestPath;
$_SERVER['SCRIPT_NAME'] = $requestPath;
$_SERVER['SCRIPT_FILENAME'] = $legacyScript;
$_SERVER['SYMFONY_CONTAINER'] = $container;
chdir(dirname($legacyScript));
if ($prepend) {
/** @noinspection PhpIncludeInspection */
require $prepend;
}
/** @noinspection PhpIncludeInspection */
require $legacyScript;
if ($append) {
/** @noinspection PhpIncludeInspection */
require $append;
}
};
return StreamedResponse::create($requireLegacyScript);
}
示例3: testCreate
public function testCreate()
{
$response = StreamedResponse::create(function () {
}, 204);
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\StreamedResponse', $response);
$this->assertEquals(204, $response->getStatusCode());
}