Skip to content

Latest commit

 

History

History
179 lines (120 loc) · 5.81 KB

readme.md

File metadata and controls

179 lines (120 loc) · 5.81 KB

Export Bundle

Description

A utlity Symfony bundle to help with export data from Symfony applications.

It allows exports by default in the formats csv and xlsx. With the ability to add support for more formats via custom Exporters.

This bundle allows you to export data via 3 methods: Direct Download, Background Download, Background Email. More info here

Getting Started

To add to your project

composer require parthenon/export-bundle

Requirements

  • PHP 8.1+
  • Symfony 6+

Support

Support is provided via GitHub, Slack, and Email.

If you have a commercial license you will be able to list the GitHub accounts that you want to link to the license. This means when an issue is created by an account linked to a commercial license they will get priority support. All other issues will be given best effort support.

Issues we will provide support and fixes for:

  • Defects/Bugs
  • Performance issues
  • Documentation fixes/improvements
  • Lack of flexibility
  • Feature requests

Example Usage

namespace App\Controller;

use App\Export\DemoDataProvider;
use Parthenon\Export\Engine\EngineInterface;
use Parthenon\Export\Exporter\ExporterManagerInterface;
use Parthenon\Export\Exporter\ExporterManagerInterface;
use Parthenon\Export\Response\ResponseConverterInterface;
use Parthenon\Export\Entity\BackgroundExportRequest;
use Parthenon\Export\Repository\BackgroundExportRequestRepositoryInterface;

class ExportController
{
    public function export(Request $request, EngineInterface $engine, ResponseConverterInterface $responseConverter)
    {
        $exportName = $request->get("name");
        $exportFormat = $request->get("format");

        $exportRequest = new ExportRequest($exportName, $exportFormat, DemoDataProvider::class, $parameters);

        $response = $engine->process($exportRequest);

        return $responseConverter->convert($response);
    }
    
    public function downloadWaiting(Request $request, LoggerInterface $logger, BackgroundExportRequestRepositoryInterface $backgroundExportRequestRepository, Environment $twig)
    {
        $id = $request->get('id');

        /** @var BackgroundExportRequest $backgroundExportRequest */
        $backgroundExportRequest = $backgroundExportRequestRepository->findById($id);

        $downloadUrl = $backgroundExportRequest->getExportedFilePath();

        if ($downloadUrl) {
            return new RedirectResponse($downloadUrl);
        } else {
            return new Response($twig->render('export_background_download.html.twig'));
        }
    }
}

Data Provider

<?php

namespace App\Export;

use Parthenon\Export\DataProvider\DataProviderInterface;

class DemoDataProvider extends DataProviderInterface 
{
    public function __construct(
        private DemoDataRepositoryInterface $repository,
    ) {
    }

    public function getData(ExportRequest $exportRequest): iterable
    {
        return $this->repository->findAll();
    }
}

Documentation

You can find the full documentation in Parthenon Docs for Export

Export Engines

Direct Download

This is where the export is generated within the HTTP request and a download file is provided.

Background Download

This is where the export is generated within the background via Symfony Messenger and once the download is generated it's saved to a storage area and then the user can download it.

Configuration

The file uploading part of the background download engine is handled by the common module of Parthenon. The full documentation can be found here.

If you want to save the file to a local folder the configuration below can help.

parthenon:
  common:
    uploader:
      default:
        provider: local
        naming_strategy: time_random
        local:  
          path: "%kernel.project_dir%/public/uploads"

Background Email

This is where the export is generated within the background via Symfony Messenger. Once the export is generated it's emailed to the requesting user.

The email sending part of this engine is handled by the Notification module of Parthenon. The full documentation can be found at here

If you're already using Symfony Mailer and just want that to be used then the configuration below is what is needed.

parthenon:
  notification:
    type: symfony

FAQ

Is this Open Source?

Yes. This bundle has been released under the GPL V3 License.

Why is this Open Source while Parthenon is source available?

This has been released under an open source license for two reasons. One is that data exports is a source of technical debt for many tech teams and I wanted this to be useful to as many people as possible as I feel it really helps solve the issue for many teams.

The other reason is to see the usage and bug reports, etc from an open source version.

If this is released under GPL and Parthenon contains this code, shouldn't Parthenon legally be GPL?

No. As the copyright holder the GPL license doesn't apply to me and I'm legally entitled to distribute it how I want, relicense it, etc. GPL only affects people who fork this bundle.

What support is available for this bundle?

This bundle comes with community level support, which is best efforts. You can get a professional support by paying for a Parthenon license. Which is $250 per developer per year.