1. Go to this page and download the library: Download yethee/enum-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/ */
yethee / enum-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Biplane\EnumBundle\BiplaneEnumBundle(),
// ...
);
}
use Biplane\EnumBundle\Enumeration\Enum;
class UserRoles extends Enum
{
const MEMBER = 'ROLE_MEMBER';
const ADMIN = 'ROLE_ADMIN';
public static function getPossibleValues()
{
return array(static::MEMBER, static::ADMIN);
}
public static function getReadables()
{
return array(static::MEMBER => 'Member', static::ADMIN => 'Admin');
}
}
use Biplane\EnumBundle\Enumeration\FlaggedEnum;
class Permissions extends FlaggedEnum
{
const READ = 1;
const WRITE = 2;
const REMOVE = 4;
const ALL = 7;
public static function getPossibleValues()
{
return array(static::READ, static::WRITE, static::REMOVE);
}
public static function getReadables()
{
return array(
static::READ => 'Read',
static::WRITE => 'Write',
static::REMOVE => 'Remove',
static::ALL => 'All permissions',
);
}
}
use Doctrine\ORM\Mapping as ORM;
class User
{
/**
* @ORM\Column(type="string")
*/
private $role;
public function getRole()
{
return UserRoles::create($this->role);
}
public function setRole(UserRoles $role)
{
$this->role = $role->getValue();
}
}
namespace Acme\DemoBundle\Doctrine\Type;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class RoleType extends StringType
{
public function getName()
{
return 'role_enum';
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return $value->getValue();
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}
return UserRoles::create($value);
}
}
use Doctrine\ORM\Mapping as ORM;
class User
{
/**
* @ORM\Column(type="role_enum")
*/
private $role;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.