PHP code example of eprofos / reverse-engineering-bundle

1. Go to this page and download the library: Download eprofos/reverse-engineering-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/ */

    

eprofos / reverse-engineering-bundle example snippets



// config/bundles.php
return [
    // ... other bundles
    Eprofos\ReverseEngineeringBundle\ReverseEngineeringBundle::class => ['all' => true],
];



declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\Enum\UserStatusEnum;
use DateTimeInterface;

/**
 * User entity generated automatically from database table 'users'
 */
#[ORM\Entity(repositoryClass: App\Repository\UserRepository::class)]
#[ORM\Table(name: 'users')]
class User
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer', nullable: false)]
    private int $id;

    #[ORM\Column(type: 'string', length: 255, nullable: false)]
    private string $email;

    #[ORM\Column(type: 'string', length: 100, nullable: true)]
    private ?string $firstName = null;

    #[ORM\Column(type: 'string', length: 100, nullable: true)]
    private ?string $lastName = null;

    #[ORM\Column(type: 'string', enumType: UserStatusEnum::class, nullable: false)]
    private UserStatusEnum $status = UserStatusEnum::PENDING;

    #[ORM\Column(type: 'datetime', nullable: false)]
    private DateTimeInterface $createdAt;

    // Getters and setters...
    public function getId(): int
    {
        return $this->id;
    }

    public function getEmail(): string
    {
        return $this->email;
    }

    public function setEmail(string $email): static
    {
        $this->email = $email;
        return $this;
    }

    public function getStatus(): UserStatusEnum
    {
        return $this->status;
    }

    public function setStatus(UserStatusEnum $status): static
    {
        $this->status = $status;
        return $this;
    }

    // ... other getters and setters
}



declare(strict_types=1);

namespace App\Enum;

/**
 * UserStatusEnum generated automatically from MySQL ENUM column
 */
enum UserStatusEnum: string
{
    case ACTIVE = 'active';
    case INACTIVE = 'inactive';
    case PENDING = 'pending';
}



declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\Enum\ProductStatusEnum;
use DateTimeInterface;

/**
 * Product entity generated automatically from database table 'products'
 */
#[ORM\Entity(repositoryClass: App\Repository\ProductRepository::class)]
#[ORM\Table(name: 'products')]
class Product
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer', nullable: false)]
    private int $id;

    #[ORM\Column(type: 'string', length: 255, nullable: false)]
    private string $name;

    #[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: false)]
    private string $price;

    #[ORM\Column(type: 'string', enumType: ProductStatusEnum::class, nullable: false)]
    private ProductStatusEnum $status = ProductStatusEnum::DRAFT;

    #[ORM\Column(type: 'datetime', nullable: false)]
    private DateTimeInterface $createdAt;

    #[ORM\ManyToOne(targetEntity: Category::class)]
    #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id', nullable: false)]
    private Category $category;

    // Getters and setters...
    public function getCategory(): Category
    {
        return $this->category;
    }

    public function setCategory(Category $category): static
    {
        $this->category = $category;
        return $this;
    }

    // ... other getters and setters
}

// Type-safe with IDE autocompletion
$user = new User();
$user->setStatus(UserStatusEnum::ACTIVE);

// Compile-time error prevention
$user->setStatus('invalid'); // PHP Fatal Error

// Easy value checking
if ($user->getStatus() === UserStatusEnum::ACTIVE) {
    // Handle active user
}

// All enum values available
foreach (UserStatusEnum::cases() as $status) {
    echo $status->value . PHP_EOL;
}

#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
private User $user;

#[ORM\ManyToOne(targetEntity: Category::class)]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id')]
private ?Category $parent = null;
bash
# Validate syntax and Doctrine mapping
find src/Entity -name "*.php" -exec php -l {} \;
php bin/console doctrine:schema:validate
bash
# Increase memory limit for large databases
php -d memory_limit=512M bin/console eprofos:reverse:generate