PHP code example of nepada / consistence-doctrine

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

    

nepada / consistence-doctrine example snippets


/**
 * @phpstan-extends \Nepada\ConsistenceDoctrine\StringEnumType<\FooEnum>
 */
class FooEnumType extends \Nepada\ConsistenceDoctrine\StringEnumType
{

    protected function getEnumClassName(): string
    {
        return \FooEnum::class;
    }

}

$result = $repository->createQueryBuilder('bar')
    ->select('bar.foo') // FooEnum instances are created during hydratation
    ->where('bar.foo = :fooEnum')
    ->setParameter('fooEnum', \FooEnum::get(\FooEnum::VALUE), \FooEnum::class) // enum instance gets serialized
    ->getQuery()
    ->setMaxResults(1)
    ->getSingleResult();
 php
\Doctrine\DBAL\Types\Type::addType(\FooEnum::class, \FooEnumType::class);
 php
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class SomeEntity
{

    /** @ORM\Column(type=\FooEnum::class, nullable=false) */
    private \FooEnum $foo;

    // ...

}