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

Entity Data List Console Bundle Laravel Package

danilovl/entity-data-list-console-bundle

Symfony bundle adding a console command to list Doctrine ORM entity records in a formatted table. Configure which fields and associations to display, with automatic date formatting and pagination via --limit and --offset. Works by passing the entity class name.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require danilovl/entity-data-list-console-bundle
    

    Register the bundle in config/bundles.php:

    Danilovl\EntityDataListConsoleBundle\EntityDataListConsoleBundle::class => ['all' => true]
    
  2. First Use Case: Run the default command to inspect an entity (e.g., App\Entity\User):

    php bin/console danilovl:entity-data-list:orm App\Entity\User
    

    This displays a tabular output of the first 10 records with default fields.


Where to Look First

  • Command Reference: Check danilovl:entity-data-list:orm for core functionality.
  • Customization Guide: Review EntityDataListCommand abstract class for extending behavior.
  • Gedmo Support: Use OrmTranslatableEntityDataListCommand for translatable entities (e.g., Gedmo\Translatable).

Implementation Patterns

Core Workflows

  1. Basic Entity Inspection:

    php bin/console danilovl:entity-data-list:orm App\Entity\Order --limit=50
    
    • Outputs a paginated table of Order entities with default fields.
  2. Field Customization: Extend EntityDataListCommand to define specific fields:

    protected function getFields(ClassMetadata $metadata): array {
        return ['id', 'orderNumber', 'customer.email', 'totalAmount'];
    }
    
    • Supports dot notation for related fields (e.g., customer.email).
  3. Association Handling:

    • Ignore Associations:
      php bin/console danilovl:entity-data-list:orm App\Entity\Product --associations-ignore=reviews,images
      
    • Limit Association Items:
      php bin/console danilovl:entity-data-list:orm App\Entity\Product --associations-limit=2
      
  4. Custom Commands: Create reusable commands for frequent queries:

    #[AsCommand('app:orders-export')]
    class OrdersExportCommand extends EntityDataListCommand {
        protected function getEntityClass(): string { return Order::class; }
        protected function getFields(ClassMetadata $metadata): array {
            return ['id', 'createdAt', 'status', 'customer.name'];
        }
    }
    

Integration Tips

  • Symfony Events: Hook into console.command events to log command usage or validate inputs.
  • Doctrine Extensions: Pair with Stof\DoctrineExtensionsBundle for advanced field types (e.g., Sluggable, Timestampable).
  • Output Formatting: Override renderRow() to customize table formatting (e.g., add colors, truncate long text):
    protected function renderRow(array $row): string {
        return sprintf("<fg=blue>%s</> | %s", $row['id'], substr($row['description'], 0, 30));
    }
    

Gotchas and Tips

Pitfalls

  1. Performance:

    • Avoid fetching large datasets without --limit. Use --offset cautiously for deep pagination.
    • Fix: Add a default limit in your custom command:
      protected function getLimit(): int { return 100; }
      
  2. Circular References:

    • Deeply nested associations (e.g., User → Orders → Products → Categories) may cause infinite loops.
    • Fix: Explicitly ignore problematic associations:
      --associations-ignore=orders.products.categories
      
  3. Locale Mismatches:

    • OrmTranslatableEntityDataListCommand defaults to en_US. Override getLocale() if your app uses a different default:
      protected function getLocale(): string { return 'fr_FR'; }
      
  4. Field Access Errors:

    • Non-public properties or getter methods may fail silently.
    • Fix: Use getFields() to explicitly list accessible fields or implement __get() in entities.

Debugging

  • Enable Verbose Output:

    php bin/console danilovl:entity-data-list:orm App\Entity\User -v
    

    Reveals SQL queries and entity hydration issues.

  • Check Metadata: Inspect Doctrine metadata for field names:

    $metadata = $this->entityManager->getClassMetadata(User::class);
    print_r($metadata->getFieldNames());
    
  • Test with Simple Entities: Start with entities without complex associations (e.g., User) to isolate issues.


Extension Points

  1. Custom Field Processors: Override processRow() to transform data before rendering:

    protected function processRow(object $entity, array $fields, ClassMetadata $metadata): array {
        $row = parent::processRow($entity, $fields, $metadata);
        $row['price'] = '$' . number_format($row['price'], 2);
        return $row;
    }
    
  2. Dynamic Field Selection: Use runtime logic to select fields:

    protected function getFields(ClassMetadata $metadata): array {
        return array_filter($metadata->getFieldNames(), fn($field) => str_contains($field, 'date'));
    }
    
  3. Export Formats: Extend the command to output CSV/JSON by overriding renderTable():

    protected function renderTable(array $rows): string {
        $csv = fopen('php://temp', 'r+');
        foreach ($rows as $row) {
            fputcsv($csv, $row);
        }
        rewind($csv);
        return stream_get_contents($csv);
    }
    

Config Quirks

  • Bundle Registration: Ensure the bundle is enabled in bundles.php after Doctrine bundles (e.g., Doctrine\Bundle\DoctrineBundle).

  • PHP 8.5+ Features: Leverage named arguments in custom commands:

    #[AsCommand('app:user-list', description: 'List users with custom fields')]
    
  • Environment Variables: Inject configuration via Symfony’s ParameterBagInterface:

    public function __construct(private ParameterBagInterface $params) {}
    protected function getLimit(): int { return (int)$this->params->get('user_list_limit', 50); }
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui