PHP code example of danilovl / entity-data-list-console-bundle

1. Go to this page and download the library: Download danilovl/entity-data-list-console-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

danilovl / entity-data-list-console-bundle example snippets


namespace App\Command;

use App\Entity\User;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand('app:user-data-list')]
class UserDataListCommand extends EntityDataListCommand
{
    protected function getEntityClass(): ?string
    {
        return User::class;
    }

    protected function getLimit(): int
    {
        return 20;
    }

    protected function getAssociationsIgnore(): int
    {
        return 1; 
    }

    protected function getFields(ClassMetadata $metadata): array
    {
        return ['id', 'username', 'email', 'createdAt'];
    }

    protected function processRow(object $entity, array $fields, ClassMetadata $metadata): array
    {
        $row = parent::processRow($entity, $fields, $metadata);

        if (isset($row['createdAt'])) {
            $row['createdAt'] = $row['createdAt']->format('Y-m-d');
        }

        return $row;
    }
    
    // or customize another logic
}

protected function getLocale(): string
{
    return 'en_US'; // Gedmo default locale is en_US
}

 declare(strict_types=1);

namespace App\Command;

use App\Domain\Product\Entity\Product;
use Danilovl\EntityDataListConsoleBundle\Command\OrmTranslatableEntityDataListCommand;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand('danilovl:entity-data-list:product', 'Render the database data of a product entity.')]
class ProductListCommand extends OrmTranslatableEntityDataListCommand
{
    protected function getEntityClass(): ?string
    {
        return Product::class;
    }
}
 php

// config/bundles.php

return [
    // ...
    Danilovl\EntityDataListConsoleBundle\EntityDataListConsoleBundle::class => ['all' => true]
];
bash
 php bin/console danilovl:entity-data-list:orm App\\Entity\\User