9
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SymfonyAdvent Calendar 2017

Day 16

よく使いそうなDoctrineEnum集

Last updated at Posted at 2017-12-15

休日なので気楽に小ネタをぶっ込みます。

今後も使いまわしたい、DoctrineEnumTypeコピペ集です。(探したけど見つからなかった)

マサカリ歓迎です!

DoctrineEnumBundleについて

MySQLのEnum型をMappingで利用したいときに使うやつです。
詳細は本家を。使い方もカンタンです。

DoctrineEnumType集

本編です。コピペしてご利用下さい。

都道府県の一覧

<?php

namespace AppBundle\DBAL\Types;

use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;

final class PrefectureType extends AbstractEnumType
{
    public const HOKKAIDO  = '北海道';
    public const AOMORI    = '青森県';
    public const IWATE     = '岩手県';
    public const MIYAGI    = '宮城県';
    public const AKITA     = '秋田県';
    public const YAMAGATA  = '山形県';
    public const FUKUSHIMA = '福島県';
    public const IBARAKI   = '茨城県';
    public const TOCHIGI   = '栃木県';
    public const GUMMA     = '群馬県';
    public const SAITAMA   = '埼玉県';
    public const CHIBA     = '千葉県';
    public const TOKYO     = '東京都';
    public const KANAGAWA  = '神奈川県';
    public const NIIGATA   = '新潟県';
    public const TOYAMA    = '富山県';
    public const ISHIKAWA  = '石川県';
    public const FUKUI     = '福井県';
    public const YAMANASHI = '山梨県';
    public const NAGANO    = '長野県';
    public const GIFU      = '岐阜県';
    public const SHIZUOKA  = '静岡県';
    public const AICHI     = '愛知県';
    public const MIE       = '三重県';
    public const SHIGA     = '滋賀県';
    public const KYOTO     = '京都府';
    public const OSAKA     = '大阪府';
    public const HYOGO     = '兵庫県';
    public const NARA      = '奈良県';
    public const WAKAYAMA  = '和歌山県';
    public const TOTTORI   = '鳥取県';
    public const SHIMANE   = '島根県';
    public const OKAYAMA   = '岡山県';
    public const HIROSHIMA = '広島県';
    public const YAMAGUCHI = '山口県';
    public const TOKUSHIMA = '徳島県';
    public const KAGAWA    = '香川県';
    public const EHIME     = '愛媛県';
    public const KOUCHI    = '高知県';
    public const FUKUOKA   = '福岡県';
    public const SAGA      = '佐賀県';
    public const NAGASAKI  = '長崎県';
    public const KUMAMOTO  = '熊本県';
    public const OOITA     = '大分県';
    public const MIYAZAKI  = '宮崎県';
    public const KAGOSHIMA = '鹿児島県';
    public const OKINAWA   = '沖縄県';

    protected static $choices = [
        self::HOKKAIDO  => '北海道',
        self::AOMORI    => '青森県',
        self::IWATE     => '岩手県',
        self::MIYAGI    => '宮城県',
        self::AKITA     => '秋田県',
        self::YAMAGATA  => '山形県',
        self::FUKUSHIMA => '福島県',
        self::IBARAKI   => '茨城県',
        self::TOCHIGI   => '栃木県',
        self::GUMMA     => '群馬県',
        self::SAITAMA   => '埼玉県',
        self::CHIBA     => '千葉県',
        self::TOKYO     => '東京都',
        self::KANAGAWA  => '神奈川県',
        self::NIIGATA   => '新潟県',
        self::TOYAMA    => '富山県',
        self::ISHIKAWA  => '石川県',
        self::FUKUI     => '福井県',
        self::YAMANASHI => '山梨県',
        self::NAGANO    => '長野県',
        self::GIFU      => '岐阜県',
        self::SHIZUOKA  => '静岡県',
        self::AICHI     => '愛知県',
        self::MIE       => '三重県',
        self::SHIGA     => '滋賀県',
        self::KYOTO     => '京都府',
        self::OSAKA     => '大阪府',
        self::HYOGO     => '兵庫県',
        self::NARA      => '奈良県',
        self::WAKAYAMA  => '和歌山県',
        self::TOTTORI   => '鳥取県',
        self::SHIMANE   => '島根県',
        self::OKAYAMA   => '岡山県',
        self::HIROSHIMA => '広島県',
        self::YAMAGUCHI => '山口県',
        self::TOKUSHIMA => '徳島県',
        self::KAGAWA    => '香川県',
        self::EHIME     => '愛媛県',
        self::KOUCHI    => '高知県',
        self::FUKUOKA   => '福岡県',
        self::SAGA      => '佐賀県',
        self::NAGASAKI  => '長崎県',
        self::KUMAMOTO  => '熊本県',
        self::OOITA     => '大分県',
        self::MIYAZAKI  => '宮崎県',
        self::KAGOSHIMA => '鹿児島県',
        self::OKINAWA   => '沖縄県',
    ];
}

性別

まぁ、これは2つしかないので楽ですけど。

<?php

namespace AppBundle\DBAL\Types;

use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;

final class GenderType extends AbstractEnumType
{
    public const MALE   = 'male';
    public const FEMALE = 'female';

    protected static $choices = [
        self::MALE   => '男性',
        self::FEMALE => '女性',
   ];
}

※LGBTへの配慮が云々、とか思った方は適当に環境に合わせて書き換えてご利用下さいませ

他にもあるかも

これもEnumにしておけば使えそう、などあればお気軽にご指摘下さいませ。
頑張って作ります :muscle::triumph:

9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?