Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Export Bundle Laravel Package

bugloos/export-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require bugloos/export-bundle
    

    Ensure your project meets the requirements: PHP 7.4+ and Symfony 4.4+.

  2. Enable the Bundle Add to config/bundles.php:

    Bugloos\ExportBundle\BugloosExportBundle::class => ['all' => true],
    
  3. First Export Use Case Create a controller method to export a simple array as CSV:

    use Bugloos\ExportBundle\Exporter\ExporterInterface;
    use Symfony\Component\HttpFoundation\Response;
    
    public function export(ExporterInterface $exporter): Response
    {
        $data = [
            ['Name', 'Email'],
            ['John Doe', 'john@example.com'],
        ];
    
        return $exporter->export($data, 'export.csv');
    }
    
  4. Key Classes to Explore

    • ExporterInterface: Core interface for exports.
    • Exporter: Default implementation (check src/Exporter/Exporter.php).
    • Format\Csv: CSV-specific logic (if available in future updates).

Implementation Patterns

Common Workflows

  1. Exporting Collections Convert Doctrine collections or Eloquent results to arrays:

    $users = $entityManager->getRepository(User::class)->findAll();
    $exportData = array_map(fn(User $user) => [$user->getName(), $user->getEmail()], $users);
    return $exporter->export($exportData, 'users.csv');
    
  2. Dynamic Headers Use a callback to generate headers dynamically:

    $headers = array_map(fn($key) => ucfirst($key), array_keys($data[0]));
    $exportData = array_merge([$headers], $data);
    
  3. Streaming Large Datasets For memory efficiency, stream row-by-row (if supported in future versions):

    $exporter->streamExport($data, 'large_export.csv');
    
  4. Integration with Symfony Forms Use form data directly:

    $formData = $form->getData();
    $exportData = array_map(fn($item) => [$item['name'], $item['value']], $formData);
    

Advanced Patterns

  • Custom Formats: Extend Format\AbstractFormat to add new formats (e.g., JSON, XML).
  • Event Listeners: Hook into kernel.response to auto-export based on routes.
  • Twig Integration: Pass export logic to templates via services.

Gotchas and Tips

Pitfalls

  1. No Active Maintenance

    • Last release in 2022; verify compatibility with Symfony 6.x/Laravel (if adapted).
    • Test thoroughly—assume undocumented edge cases.
  2. Limited Documentation

    • Assume no built-in support for:
      • Complex Excel features (formulas, styling).
      • Streaming large files (check future PRs).
    • Refer to Symfony’s HttpFoundation for fallback responses.
  3. CSV Quirks

    • Escape special characters manually (e.g., commas, quotes) if not handled by the bundle.
    • Example fix:
      $escapedData = array_map(
          fn($row) => array_map('str_getcsv', $row),
          $data
      );
      
  4. Dependency Conflicts

    • Avoid conflicts with symfony/csv or phpoffice/phpexcel if installed.

Debugging Tips

  • Check Response Headers Ensure Content-Disposition is set correctly:
    $response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
    
  • Log Exported Data Validate data structure before export:
    \Log::debug('Export data:', ['data' => $data]);
    
  • Fallback to Symfony’s CSV If the bundle fails, use Symfony’s built-in:
    use Symfony\Component\HttpFoundation\StreamedResponse;
    $response = new StreamedResponse();
    $response->setCallback(fn() => $this->streamCsv($data));
    

Extension Points

  1. Add New Formats Extend AbstractFormat and register as a service:

    # config/services.yaml
    Bugloos\ExportBundle\Format\JsonFormat: ~
    
  2. Custom Exporter Implement ExporterInterface for specialized logic:

    class CustomExporter implements ExporterInterface {
        public function export(array $data, string $filename): Response {
            // Custom logic
        }
    }
    
  3. Configuration Override defaults in config/packages/bugloos_export.yaml (if supported):

    bugloos_export:
        default_format: 'csv'
        delimiter: ';'
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle