zinvapel / enumeration
An enumeration class
1.0.0
2020-12-16 19:27 UTC
Requires
- php: ^7.4 || ^8.0
This package is auto-updated.
Last update: 2025-04-17 04:54:53 UTC
README
Usage examples:
- Own enum:
<?php namespace App\Status; use Zinvapel\Enumeration\BaseEnumeration; class Status extends BaseEnumeration { public const ACTIVE = 'active'; public const INACTIVE = 'inactive'; protected $names = [ self::ACTIVE => 'Active', self::INACTIVE => 'Inactive', ]; /** * @return bool */ public function isActive(): bool { return $this->eq(self::ACTIVE); } }
- In code:
... $status = new Status(Status::INACTIVE); if ($status->neq(new Status(Status::ACTIVE))) { // do something with not active status } ...
- With static constructors:
<?php namespace App\Status; use Zinvapel\Enumeration\BaseEnumeration; class Status extends BaseEnumeration { public const ACTIVE = 'active'; protected $names = [ self::ACTIVE => 'Active', ]; /** * @return Status */ public static function active(): Status { return new self(self::ACTIVE); } }