Slide 1

Slide 1 text

Bye-Bye
 Magic Number ʙʮࣙॻʯΛ࡞ͬͨ࿩ʙ Hideki Kinjyo twitter: @o0h_ / github: o0h

Slide 2

Slide 2 text

ࣗݾ঺հ • ίωώτגࣜձࣾ • αʔόʔαΠυΤϯδχΞ • ओʹCakePHPͳͲ

Slide 3

Slide 3 text

ࠓ೔͓࿩͢Δ͜ͱ • ϚδοΫφϯόʔʹউͭͧɾɾɾʂ • ͦͷͨΊʹ”Ϟϊ”Λ࡞Γ·ͨ͠

Slide 4

Slide 4 text

Έͳ͞Μɺ
 ΞϓϦέʔγϣϯͷʮఆ਺ʯ ͷ؅ཧͲ͏͍ͯ͠·͔͢ʁ ϚδοΫφϯόʔ తͳ΍ͭ

Slide 5

Slide 5 text

͜͏͍͏΍ͭ • Ϣʔβʔͷొ࿥ঢ়ଶ͕ɾɾ • 0: ϝʔϧΞυϨε֬ೝ଴ͪ • 1: ࢧ෷͍৘ใ֬ೝ଴ͪ • 2: ొ࿥׬ྃ

Slide 6

Slide 6 text

ᶃϚδοΫφϯόʔ͸ਏ͍

Slide 7

Slide 7 text

ᶃϚδοΫφϯόʔ͸ਏ͍ • ಡΜͰ͍ͯʮಥવग़͖ͯͨʯײ͡ • ʮಛผͳҙຯͷ͋Δ஋ʯʁʮྔͱ͔౓߹͍Λද͍ͯ͠ Δ੔਺஋ʯʁ • ൑ผ͕ͮ͠Β͍ • grep͠ʹ͘͞ => ϦϑΝΫλ͠ʹ͘͞ • etc… (άάͬͨΒ৭ʑग़ͯ͘ΔͷͰׂѪ

Slide 8

Slide 8 text

ᶄϞσϧΫϥεͷఆ਺ʹʂ

Slide 9

Slide 9 text

ᶄϞσϧΫϥεͷఆ਺ʹʂ • ୯ޠͰ໊લ͕෇͚ΒΕ͍ͯΔ͔Β෼͔Γ΍͢ ͍Ͷʂ • ؔ࿈͢Δ஌ࣝΛ1Օॴʹ·ͱΊΒΕͯ෼͔Γ΍ ͍͢Ͷʂ(scoped, contextual)

Slide 10

Slide 10 text

ᶄϞσϧΫϥεͷఆ਺ʹʂ • ʮͲͷΫϥεʹஔ͔͘ʯ͸೰·͍͠ • ͋ΕɺTableʹ࣋ͨͤΔʁEntityʹ࣋ͨͤ Δʁ • ͦ΋ͦ΋Ϟσϧͱؔ࿈͠ͳ͍஌ࣝ͸Ͳ͏͢Δʁ

Slide 11

Slide 11 text

ᶅConfigureΫϥεͰѻ͏ʂ

Slide 12

Slide 12 text

ᶅConfigureΫϥεͰѻ͏ʂ • ͜ΕͰ΋໊෇͚͸Մೳʂ • ֊૚Խ΋Ͱ͖Δʂ • ʮͲͷΫϥεʹଐ͢Δ͔ʯΛҙࣝͤͣʹ͓͚ Δʂ

Slide 13

Slide 13 text

ᶅConfigureΫϥεͰѻ͏ʂ • ΍Ζ͏ͱࢥ͑͹ॻ͖׵͑ΒΕͪΌ͏ΑͶ… • ७ਮͳʮΞϓϦέʔγϣϯͷઃఆʯͱ
 ͍ࠞͬͯ͟ΔͷɺԿͱͳ͘ؾ࣋ͪѱ͍͔΋… • ෆ༻ҙʹ௕͘ͳΓ͕ͪɻ • ͪͳΈʹɺ
 ίωώτʹ͸2,181ߦͷconstants.php͕͋Γ·͢

Slide 14

Slide 14 text

ͳΜ͔ྑ͍ͷͳ͍ͷ͔ͳʂ

Slide 15

Slide 15 text

ͭͬͯ͘Έͨʂ

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

ͳΜͰ͔͢ • ఆ਺ΫϥεΛϦονʹ͠·ͨ͠Έ͍ͨͳ΋ͷ • ΫϥεΛఆٛͯ͠
 ʮ໊લʯͱʮ஋ʯͷએݴΛ͓ͯ͘͠ • ʮࣙॻʯ͕஌͍ͬͯΔ৘ใΛ
 ʮEnumʯͱͯ͠औΓग़ͤΔΑ͏ʹͳΔ • PHPʹ͸ྻڍܕ͕ͳ͍͔ΒΦϨΦϨ࣮૷

Slide 18

Slide 18 text

ʮࣙॻʯͷ࡞Γํ • AbstractΫϥεΛܧঝͯ͠ • `ENUM_` prefixΛ࣋ͬͨconstΛએݴ͢Δ

Slide 19

Slide 19 text

ʮࣙॻʯͷ࡞Γํ

Slide 20

Slide 20 text

ʮࣙॻʯͷ࢖͍ํ

Slide 21

Slide 21 text

ࣙॻͷԠ༻ᶃʮTypeʯ • Database\Type\EnumType • marshal/toPHPͰEnumΛѻ͑ΔΑ͏ʹ͢Δ

Slide 22

Slide 22 text

ࣙॻͷԠ༻ᶃʮEnumTypeʯ

Slide 23

Slide 23 text

ࣙॻͷԠ༻ᶃʮEnumTypeʯ

Slide 24

Slide 24 text

ࣙॻͷԠ༻ᶄʮValidationʯ • ʮରԠ͢Δࣙॻʹએݴ͞Ε͍ͯΔ͔ʯΛ
 νΣοΫ͢ΔValidationProvider • ʮ͜ͷྻ͸͜ͷࣙॻʯͱ͍͏ͷΛ
 ηοτ͓ͯ͘͠ͱɺະએݴͳ஋Λڋ൱Ͱ͖Δ

Slide 25

Slide 25 text

ࣙॻͷԠ༻ᶄʮValidationʯ

Slide 26

Slide 26 text

ࣙॻͷԠ༻ᶄʮValidationʯ

Slide 27

Slide 27 text

·ͱΊ • લੈ୅ͷΞϓϦέʔγϣϯͰ
 ϚδοΫφϯόʔ΍constansͷരൃ͕ਏͯ͘ɾɾ • CakePHP3ͷPJ্ཱͪ͛࣌ʹ
 ݁ߏͳίετΛ͔͚ͭͭɺ͜ͷػߏͷ࡞੒Λߦ͍·ͨ͠ • ݁Ռɺॻ͖ํ͕౷Ұ͞Ε͍͍ͯײ͡ • ͱΓΘ͚ɺCakePHP3ͷORMपΓ͸͔ͳΓڧԽ͞Ε͍ΔͷͰ
 Type/ValidationपΓͱͷ࿈ܞ͕ศར • ಠཱͨ͠ϨϙδτϦʹ͓͍ͨࣄͰϙʔλϏϦςΟ

Slide 28

Slide 28 text

͝ਗ਼ௌɺ
 ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ
 ࣮૷ͷ࿩ͱ͔͍ͯ͠ͳ͍ͷͰ
 ͓ؾܰʹฉ͍͍ͯͩ͘͞