Skip to content

Instantly share code, notes, and snippets.

@Mo3g4u
Created February 8, 2017 09:41
Show Gist options
  • Save Mo3g4u/c114db05a1646318bb8155415470675b to your computer and use it in GitHub Desktop.
Save Mo3g4u/c114db05a1646318bb8155415470675b to your computer and use it in GitHub Desktop.
都道府県enum
class Prefecture extends Enum
{
const HOKKAIDO = "北海道";
const AOMORI = "青森";
const IWATE = "岩手";
const MIYAGI = "宮城";
const AKITA = "秋田";
const YAMAGATA = "山形";
const FUKUSHIMA = "福島";
const IBARAKI = "茨城";
const TOCHIGI = "栃木";
const GUNMA = "群馬";
const SAITAMA = "埼玉";
const CHIBA = "千葉";
const TOKYO = "東京";
const KANAGAWA = "神奈川";
const NIIGATA = "新潟";
const TOYAMA = "富山";
const ISHIKAWA = "石川";
const FUKUI = "福井";
const YAMANASHI = "山梨";
const NAGANO = "長野";
const GIFU = "岐阜";
const SHIZUOKA = "静岡";
const AICHI = "愛知";
const MIE = "三重";
const SHIGA = "滋賀";
const KYOTO = "京都";
const OSAKA = "大阪";
const HYOGO = "兵庫";
const NARA = "奈良";
const WAKAYAMA = "和歌山";
const TOTTORI = "鳥取";
const SHIMANE = "島根";
const OKAYAMA = "岡山";
const HIROSHIMA = "広島";
const YAMAGUCHI = "山口";
const TOKUSHIMA = "徳島";
const KAGAWA = "香川";
const EHIME = "愛媛";
const KOCHI = "高知";
const FUKUOKA = "福岡";
const SAGA = "佐賀";
const NAGASAKI = "長崎";
const KUMAMOTO = "熊本";
const OITA = "大分";
const MIYAZAKI = "宮崎";
const KAGOSHIMA = "鹿児島";
const OKINAWA = "沖縄";
}
abstract class Enum
{
private $scalar;
public function __construct($value)
{
$ref = new \ReflectionObject($this);
$consts = $ref->getConstants();
if (!in_array($value, $consts, true)) {
throw new \InvalidArgumentException;
}
$this->scalar = $value;
}
final public static function __callStatic($label, $args)
{
$class = get_called_class();
$const = constant("$class::$label");
return new $class($const);
}
final public function valueOf()
{
return $this->scalar;
}
final public function __toString()
{
return (string)$this->scalar;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment