PHP code example of thunderer / platenum
1. Go to this page and download the library: Download thunderer/platenum 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/ */
thunderer / platenum example snippets
declare(strict_types=1);
namespace X;
use Thunder\Platenum\Enum\ConstantsEnumTrait;
/**
* @method static static ACTIVE()
* @method static static INACTIVE()
* @method static static SUSPENDED()
* @method static static DISABLED()
*/
final class AccountStatusEnum
{
private const ACTIVE = 1;
private const INACTIVE = 2;
private const SUSPENDED = 3;
private const DISABLED = 4;
use ConstantsEnumTrait;
}
$active = AccountStatusEnum::ACTIVE();
$alsoActive = AccountStatusEnum::fromMember('ACTIVE');
$stillActive = AccountStatusEnum::fromValue(1);
assert($active === $alsoActive);
assert(true === $active->equals($alsoActive));
assert(1 === $active->getValue());
final class StatusEnum
{
use ConstantsEnumTrait;
private const ACTIVE = 1;
private const DISABLED = 2;
}
final class StatusEnum extends AbstractConstantsEnum
{
private const ACTIVE = 1;
private const DISABLED = 2;
}
/**
* @method static static ACTIVE()
* @method static static DISABLED()
*/
final class StatusEnum
{
use DocblockEnumTrait;
}
/**
* @method static static ACTIVE()
* @method static static DISABLED()
*/
final class StatusEnum extends AbstractDocblockEnum {}
#[Member('ACTIVE', 1)]
#[Member('DISABLED', 2)]
final class StatusEnum
{
use AttributeEnumTrait;
}
use Thunder\Platenum\Enum\Member;
#[Member(member: 'ACTIVE', value: 1)]
#[Member(member: 'DISABLED', value: 2)]
final class StatusEnum extends AbstractAttributeEnum {}
final class StatusEnum
{
use StaticEnumTrait;
private static $mapping = [
'ACTIVE' => 1,
'DISABLED' => 2,
];
}
final class StatusEnum extends AbstractStaticEnum
{
private static $mapping = [
'ACTIVE' => 1,
'DISABLED' => 2,
];
}
final class Currency
{
use CallbackEnumTrait;
}
final class Currency extends AbstractCallbackEnum
{
}
Currency::initialize(fn() => [
'PLN' => 985,
'EUR' => 978,
'USD' => 840,
]);
Currency::initialize(fn() => SomeClass::CONSTANT);
Currency::initialize(fn() => $database->sql('...'));
Currency::initialize(fn() => $redis->hGetAll('...'));
Currency::initialize(fn() => json_decode(file_get_contents('...')));
// etc.
final class StatusEnum
{
use EnumTrait;
private static function resolve(): array
{
return [
'ACTIVE' => 1,
'DISABLED' => 2,
];
}
}
final class AccountStatus
{
use ConstantsEnumTrait;
private const ACTIVE = 1;
private const DISABLED = 2;
protected static function throwInvalidMemberException(string $name): void
{
throw new InvalidAccountStatusException($name);
}
protected static function throwInvalidValueException($value): void
{
throw new InvalidAccountStatusValueException($value);
}
}
PlatenumDoctrineType::registerString('currency', Currency::class);
PlatenumDoctrineType::registerInteger('accountStatus', AccountStatus::class);
final class Entity
{
public static function loadMetadata(ClassMetadata $m): void
{
$m->setPrimaryTable(['name' => 'doctrine_entity']);
$m->mapField(['fieldName' => 'id', 'type' => 'bigint', 'id' => true]);
$m->mapField(['fieldName' => 'code', 'type' => 'currency', 'columnName' => 'code']);
$m->mapField(['fieldName' => 'status', 'type' => 'accountStatus', 'columnName' => 'status']);
}
}
class YourEnum extends LibraryEnum
{
const ONE = 1;
const TWO = 2;
}
final class YourEnum
{
private const ONE = 1;
private const TWO = 2;
use EnumTrait;
}
YourEnum::ONE() === YourEnum::ONE()
YourEnum::fromValue(1) === YourEnum::ONE()
YourEnum::fromValue(1) === YourEnum::fromValue(1)
public function __wakeup()
{
$this->enum->fromInstance($this->enum);
}