@param ExportableInterface $adminList
@param string              $format

@return StreamedResponse

@throws ExportException
771081
protected function streamOutput(ExportableInterface $adminList, $format)
    {
        $response = new StreamedResponse();
        $response->setCallback(function () use ($adminList, $format) {
            $writer = WriterFactory::create($format);
            $writer->openToBrowser('export.'.$format);

            $row = [];
            /** @var Field $column */
            foreach ($adminList->getExportColumns() as $column) {
                $row[] = $this->translator->trans($column->getHeader());
            }
            $writer->addRow($row);

            $iterator = $adminList->getIterator();
            $rows = [];
            foreach ($iterator as $item) {
                if (array_key_exists(0, $item)) {
                    $itemObject = $item[0];
                } else {
                    $itemObject = $item;
                }

                $row = [];
                /** @var Field $column */
                foreach ($adminList->getExportColumns() as $column) {
                    $columnName = $column->getName();
                    $itemHelper = $itemObject;
                    if ($column->hasAlias()) {
                        $itemHelper = $column->getAliasObj($itemObject);
                        $columnName = $column->getColumnName($columnName);
                    }
                    $data = $adminList->getStringValue($itemHelper, $columnName);
                    if (null !== $column->getTemplate()) {
                        if (!$this->renderer->exists($column->getTemplate())) {
                            throw new ExportException('No export template defined for ' . get_class($data), $data);
                        }

                        $data = $this->renderer->render($column->getTemplate(), ['object' => $data]);
                    }

                    $row[] = $data;
                }
                $rows[] = $row;
            }

            $writer->addRows($rows);
            $writer->close();
        });

        return $response;
    }
98232
public function export(FormatterInterface $formatter, $filename, $outDir, $storage = 'file')
    {
        if (!is_readable($filename)) {
            throw new \InvalidArgumentException(sprintf('Document not found "%s".', $filename));
        }
        if ($formatter && $storage = $this->getStorage($storage)) {
            if ($formatter->getRegistry()->config->get(FormatterInterface::CFG_USE_LOGGED_STORAGE)) {
                $storage = new LoggedStorage($storage);
            }
            $storage->setName(basename($filename, '.mwb'));
            $storage->setOutdir(realpath($outDir) ? realpath($outDir) : $outDir);
            $storage->setBackup($formatter->getRegistry()->config->get(FormatterInterface::CFG_BACKUP_FILE));
            $writer = $this->getWriter($formatter->getPreferredWriter());
            $writer->setStorage($storage);
            if ($eol = strtolower(trim($formatter->getRegistry()->config->get(FormatterInterface::CFG_EOL)))) {
                switch ($eol) {
                    case FormatterInterface::EOL_WIN:
                        $writer->getBuffer()->setEol("\r\n");
                        break;

                    case FormatterInterface::EOL_UNIX:
                        $writer->getBuffer()->setEol("\n");
                        break;
                }
            }
            $document = new Document($formatter);
            if (strlen($logFile = $formatter->getRegistry()->config->get(FormatterInterface::CFG_LOG_FILE))) {
                $logger = new LoggerFile(array('filename' => $logFile));
            } elseif ($formatter->getRegistry()->config->get(FormatterInterface::CFG_LOG_TO_CONSOLE)) {
                $logger = new LoggerConsole();
            } else {
                $logger = new Logger();
            }
            $document->setLogger($logger);
            $document->load($filename);
            $document->write($writer);
            if ($e = $document->getError()) {
                throw $e;
            }

            return $document;
        }
    }
879829
public function format(FormatInterface $format, ?Enviroment $enviroment = null): string
    {
        $parser = ParserFactory::factory($enviroment);

        return $parser->format($format);
    }
777521
def export_admin_action(self, request, queryset):
        
        export_format = request.POST.get('file_format')

        if not export_format:
            messages.warning(request, _('You must select an export format.'))
        else:
            formats = self.get_export_formats()
            file_format = formats[int(export_format)]()

            export_data = self.get_export_data(file_format, queryset, request=request)
            content_type = file_format.get_content_type()
            response = HttpResponse(export_data, content_type=content_type)
            response['Content-Disposition'] = 'attachment; filename=%s' % (
                self.get_export_filename(file_format),
            )
            return response
180829
public function serialize($serializablePage, $format)
    {
        // check if supported serialization format
        if (!SerpPageSerializerHelper::validFormat($format, self::$supportedFormatSerialization))
            throw new \Franzip\SerpPageSerializer\Exceptions\UnsupportedSerializationFormatException('Invalid SerpPageSerializer $format: supported serialization formats are JSON, XML and YAML.');
        // typecheck the object to serialize
        if (!SerpPageSerializerHelper::serializablePage($serializablePage))
            throw new \Franzip\SerpPageSerializer\Exceptions\NonSerializableObjectException('Invalid SerpPageSerializer $serializablePage: you must supply a SerializableSerpPage object to serialize.');

        $format           = strtolower($format);
        $entries          = $this->createEntries($serializablePage, $format);
        $serializablePage = $this->prepareForSerialization($serializablePage, $format, $entries);
        $serializedPage   = $this->getSerializer()->serialize($serializablePage, $format);
        // beautify output if JSON
        $content          = ($format == 'json') ? SerpPageSerializerHelper::prettyJSON($serializedPage) : $serializedPage;
        return new SerializedSerpPage($content);
    }
400648
private function retrieveFieldDescription(AdminInterface $admin, $field)
    {
        $admin->getFormFieldDescriptions();

        $fieldDescription = $admin->getFormFieldDescription($field);

        if (!$fieldDescription) {
            throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field));
        }

        if ('sonata_type_model_autocomplete' !== $fieldDescription->getType()) {
            throw new \RuntimeException(sprintf('Unsupported form type "%s" for field "%s".', $fieldDescription->getType(), $field));
        }

        return $fieldDescription;
    }
285980
public function out($format = null)
    {
        if (0 == count($this->url)) {
            throw new Exception('No URL is set');
        }
        if (! is_null($format)) {
            $this->format($format);
        }
        if (is_null($this->response)) {
            $this->call();
        }

        return $this->parseResponse();
    }
261646
public function write( $value, $format = FALSE )
	{
		if( $format )
		{
			if( version_compare( phpversion(), '5.4.0' ) >= 0 )
				$json	= json_encode( $value, JSON_PRETTY_PRINT );
			else
				$json	= ADT_JSON_Formater::format( json_encode( $value ) );
		}
		else
			$json	= json_encode( $value );
		return FS_File_Writer::save( $this->filePath, $json );
	}
220632
public function export($page, $format)
    {
        $this->authorize('index', app('scaffold.module')->model());

        $query = app('scaffold.finder')->getQuery();

        return app('scaffold.actions')->exec('export', [$query, $format]);
    }
1327880
final protected function getFormAdminType(FormMapper $formMapper, AdminInterface $admin, $formField, $field, $fieldOptions = [], $adminOptions = [])
    {
        $adminOptions = array_merge([
            'edit' => 'list',
            'translation_domain' => 'SonataClassificationBundle',
        ], $adminOptions);

        $fieldDescription = $admin->getModelManager()->getNewFieldDescriptionInstance($admin->getClass(), $field, $adminOptions);
        $fieldDescription->setAssociationAdmin($admin);
        $fieldDescription->setAdmin($formMapper->getAdmin());
        $fieldDescription->setAssociationMapping([
            'fieldName' => $field,
            'type' => ClassMetadataInfo::MANY_TO_ONE,
        ]);

        $fieldOptions = array_merge([
            'sonata_field_description' => $fieldDescription,
            'class' => $admin->getClass(),
            'model_manager' => $admin->getModelManager(),
            'required' => false,
        ], $fieldOptions);

        return $formMapper->create($formField, ModelTypeList::class, $fieldOptions);
    }
953167
public function export(Builder $query, $format)
    {
        $method = 'to'.strtoupper($format);

        if (method_exists($this, $method)) {
            return call_user_func_array([$this, $method], [$query]);
        }

        if (method_exists($this->module, $method)) {
            return call_user_func_array([$this->module, $method], [$query]);
        }

        throw new Exception(sprintf('Don\'t know how to export to %s format.', $format));
    }
408077
public function collection(string $collection, ?string $format = null) : string {
        list($collection, $extension) = preg_split('/\.(css|js)/', $collection, 2, PREG_SPLIT_DELIM_CAPTURE);

        $group = $extension == 'css' ? 'stylesheets' : 'javascripts';

        return $this->serve($collection, $group, $format);
    }
131997
public function openStream(string $mode): StreamInterface
    {
        try {
            $res = Thrower::call('fopen', $this, $mode);
        } catch (\Exception $e) {
            throw new \RuntimeException(sprintf('Unable to open %s using mode "%s"', $this, $mode), 0, $e);
        }

        return StreamFactoryDiscovery::find()->createStream($res);
    }
1059884
public function saveSnippet(
        string $outputFile,
        string $format = self::FORMAT_NGINX
    ): bool {
        if ($this->needsCompile) {
            $this->compile();
        }

        // Are we doing a report-only header?
        $which = $this->reportOnly
            ? 'Content-Security-Policy-Report-Only'
            : 'Content-Security-Policy';

        switch ($format) {
            case self::FORMAT_NGINX:
                // In PHP < 7, implode() is faster than concatenation
                $output = \implode('', [
                    'add_header ',
                    $which,
                    ' "',
                    \rtrim($this->compiled, ' '),
                    '" always;',
                    "\n"
                ]);
                break;
            case self::FORMAT_APACHE:
                $output = \implode('', [
                    'Header add ',
                    $which,
                    ' "',
                    \rtrim($this->compiled, ' '),
                    '"',
                    "\n"
                ]);
                break;
            default:
                throw new \Exception('Unknown format: '.$format);
        }
        return \file_put_contents($outputFile, $output) !== false;
    }
814324
public function createStreamFromFile($filename, $mode = "r"){
        if(!is_string($filename) || !is_string($mode)){
            throw new \InvalidArgumentException();
        }

        if(($resource = fopen($filename, $mode)) === false){
            throw new \RuntimeException;
        }

        return $this->createStreamFromResource($resource);
    }
466065
public static function create(string $format = SerializerBuilder::DEFAULT_FORMAT) : SerializerInterface
    {
        return SerializerBuilder::instance()->setFormat($format)->build();
    }
1323826
public function listView(CrudConfigurator $crudConfigurator, array $gridFields, $allowBulkDelete, $formatNumber)
    {
        $crud = $crudConfigurator->getCrud();
        /** @var ListActionHandler $viewHandler */
        $viewHandler = $this->actionHandlers[ListActionHandler::class];
        $viewHandler->setModelClass($crud->getModelClass());
        $viewHandler->setView($this->view);
        $viewHandler->setRequest($this->request);
        $viewHandler->setGridFields($gridFields);
        $viewHandler->setActionList($crudConfigurator->getGridAction());
        $viewHandler->isAllowCrate($crud->isAllowCreate());
        $viewHandler->isAllowBulkDelete($allowBulkDelete);
        $viewHandler->isFormatNumber($formatNumber);
        $viewHandler->setListHandler($crud->getListHandler());

        return $this->getResponse($viewHandler->getView($this->driver));
    }