Kajona\System\System\EnumBase

The enum base class may be used to create php-based enum approaches.

Use it as following:

To define a new enum extend this class, defining all possible values in static function getArrValues().
Use @ method annotations to get full autocomplete support in your IDE



* @ method static TestEnum A()
* @ method static TestEnum B()

class TestEnum extends EnumBase {
protected function getArrValues() { return array("A", "B"); }
}

Later on you may access all possible enums using magical static methods, returning A
$objEnum = TestEnum::A()

Compare it using the internal equals:
$objEnum->equals(TestEnum::A())

Synopsis

class EnumBase {
  • // members
  • private string $strValue = null;
}

Members

private

  • $strValue — string

Methods

protected

  • getArrValues() — Return the array of possible, so allowed values for the current enum

public

  • __callStatic() — Helper to generate possible instances of the current enum values.
  • __toString() — Prints the enums current value
  • equals() — Use this method to compare enum-instances