Пример #1
0
 /**
  * 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');
 }
 /**
  * @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
0
 public function testCreate()
 {
     $response = StreamedResponse::create(function () {
     }, 204);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\StreamedResponse', $response);
     $this->assertEquals(204, $response->getStatusCode());
 }