PHP code example of nighten / doctrine-check

1. Go to this page and download the library: Download nighten/doctrine-check 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/ */

    

nighten / doctrine-check example snippets


use App\Kernel;
use Nighten\DoctrineCheck\Config\DoctrineCheckConfig;
use Symfony\Component\Dotenv\Dotenv;

$kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
    $kernel->boot();

    $config->addObjectManager($kernel->getContainer()->get('doctrine')->getManager());
};

#[ORM\Column(type: 'string', nullable: true)]
private ?string $code;

#[ORM\Column(type: 'integer', nullable: false, enumType: Type::class)]
private Type $type;

#[ORM\Column(type: 'boolean', nullable: false)]
private bool $deleted = false;

#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $updatedAt = null;

#[
    ORM\ManyToOne(targetEntity: User::class),
    ORM\JoinColumn(nullable: false),
]
private User $user;

#[Embeddable]
class Address
{
    #[ORM\Column(type: 'string', nullable: true)]
    private ?string $code;
}

class User
{
    #[Embedded(class: Address::class)]
    private Address $address;
    ...
}


use Symfony\Component\Uid\UuidV1;
use Symfony\Component\Uid\UuidV4;
use Symfony\Component\Uid\UuidV7;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addTypeMapping('uuid', UuidV1::class);
    $config->addTypeMapping('uuid', UuidV4::class);
    $config->addTypeMapping('uuid', UuidV7::class);
};


use App\Entity\EntityClass;
use Nighten\DoctrineCheck\Type;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addEntityClass(EntityClass::class);
};


use App\Entity\EntityClass;
use Nighten\DoctrineCheck\Type;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addExcludedEntityClasses(EntityClass::class);
};


use App\Entity\EntityClass;
use Nighten\DoctrineCheck\Type;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addIgnore(EntityClass::class, 'name', ErrorType::TYPE_WRONG_NULLABLE);
};