PHP code example of granam / string-enum

1. Go to this page and download the library: Download granam/string-enum 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/ */

    

granam / string-enum example snippets




use Doctrine\ORM\Mapping as ORM;
use Doctrineum\String\StringEnum;

/**
 * @ORM\Enity()
 */
class Person
{
    /**
     * @var int
     * @ORM\Id() @ORM\GeneratedValue(strategy="AUTO") @ORM\Column(type="integer")
     */
    private $id;
   
    /**
     * @var StringEnum
     * @ORM\Column(type="string_enum")
     */
    private $name;
    
    public function __construct(StringEnum $name)
    {
        $this->name = $name;
    }

    /**
     * @return StringEnum
     */
    public function getName()
    {
        return $this->name;
    }
}

// ... entity Money using Currency
$trueHero = new Person(StringEnum::getEnum('Don Quixote de La Mancha'));

/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager->persist($trueHero);
$entityManager->flush();
$entityManager->clear();

/** @var Currency[] $StarTracks */
$sirs = $entityManager->createQuery(
    "SELECT p FROM Person p WHERE p.name LIKE 'Don %'"
)->getResult();

var_dump($sirs[0]->getName()->getValue()); // 'Don Quixote de La Mancha';



use Doctrineum\String\StringEnumType;

StringEnumType::registerSelf();