Skip to content

Instantly share code, notes, and snippets.

@texdc
Created June 8, 2016 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texdc/cae3d56b7aed4cc2f82d8b08905319c8 to your computer and use it in GitHub Desktop.
Save texdc/cae3d56b7aed4cc2f82d8b08905319c8 to your computer and use it in GitHub Desktop.
<?php declare(strict_types=1);
/**
* @method static self AUTO()
* @method static self ASK()
* @method static self SCHEDULE()
* @method static self IGNORE()
*/
final class UpdateResponseType
{
private static $allValues = [
'AUTO', 'ASK', 'SCHEDULE', 'IGNORE'
];
private $value;
private function __construct(string $aValue)
{
$this->value = strtoupper($aValue);
}
public static function validate(string $aValue) : bool
{
return in_array(strtoupper($aValue), static::$allValues);
}
public static function fromString(string $aValue) : self
{
if (static::validate($aValue)) {
return new static($aValue);
}
}
public static function listAll()
{
foreach (static::$allValues as $value) {
yield $value => static::fromString($value);
}
}
public static function __callStatic(string $aMethod, array $args = []) : self
{
return static::fromString($aMethod);
}
public function hasValue(string $aValue) : bool
{
return $this->value === strtoupper($aValue);
}
public function isAuto() : bool
{
return $this->hasValue('AUTO');
}
public function isAsk() : bool
{
return $this->hasValue('ASK');
}
public function isSchedule() : bool
{
return $this->hasValue('SCHEDULE');
}
public function isIgnore() : bool
{
return $this->hasValue('IGNORE');
}
public function __toString() : string
{
return $this->value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment