Created
June 8, 2016 14:31
-
-
Save texdc/cae3d56b7aed4cc2f82d8b08905319c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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