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
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;
}