/** * @inheritdoc */ public static function addEnumItem(Enum $instance) { if (!isset(self::$instancesByValues[static::class])) { self::$instancesByValues[static::class] = []; } if ($instance instanceof BaseEnum) { self::$instancesByValues[static::class][$instance->getValue()] = $instance; } parent::addEnumItem($instance); }
public function testEnumProperty() { $enums = array('Yes','No'); $valid = 'Yes'; $invalid = 'Bob'; $property = new Enum('AProperty', $enums, $valid); $this->assertEquals($enums, $property->getChoices()); $property->setValue($valid); $this->assertEquals($valid, $property->getValue()); $property->setValue($invalid); $this->assertNotEquals($invalid, $property->getValue()); }
/** * Compares this enum (which has a value) to the value provided. If the value * is itself an Enum then we'll get the value of the provided enum and compare * it to our value. * * @param Enum|int|string $value * @return bool */ public final function equals($value) { if ($value instanceof Enum) { return $this->value == $value->getValue(); } return $this->value == $value; }
/** * Compares one Enum with another. * * This method is final, for more information read https://github.com/myclabs/php-enum/issues/4 * * @return bool True if Enums are equal, false if not equal */ public final function equals(Enum $enum) { return $this->getValue() === $enum->getValue(); }