PHP code example of brandembassy / doctrine-enum-type
1. Go to this page and download the library: Download brandembassy/doctrine-enum-type 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/ */
brandembassy / doctrine-enum-type example snippets
class Color extends Enum
{
public const BLACK = 'black';
public const WHITE = 'white';
public const RED = 'read';
public const GREEN = 'green';
public const BLUE = 'blue';
}
use BrandEmbassy\Doctrine\EnumType\Bridges\MarcMabeEnum\MarcMabeEnumBridge;
use BrandEmbassy\Doctrine\EnumType\EnumTypesManager;
$enumTypesManager = new EnumTypesManager(new MarcMabeEnumBridge());
$enumTypesManager->addEnumTypeDefinition('enumColor', Color::class);
$enumTypesManager->initializeEnumTypes();
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="car")
*/
final class Car
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var int
*/
private $id;
/**
* @ORM\Column(type="string")
* @var string
*/
private $brand;
/**
* @ORM\Column(type="enumColor")
* @var Color
*/
private $color;
public function __construct(string $brand, Color $color)
{
$this->brand = $brand;
$this->color = $color;
}
...
public function getColor(): Color
{
return $this->color;
}
public function setColor(Color $color): void
{
$this->color = $color;
}
}
$user = new User('Skoda', Color::get(Color::GREEN));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.