Slide 1

Slide 1 text

25෼Ͱཧղ͢Δʂ Symfonyͷັྗͱͦͷ࣮ફత׆༻๏ PHP Conference Japan 2023

Slide 2

Slide 2 text

• ֯ాɹҰฏ • גࣜձࣾDROBE • Kansai Symfony Meetup • CoderDojo ຕํ ࣗݾ঺հ

Slide 3

Slide 3 text

DROBEͷ঺հ

Slide 4

Slide 4 text

ελΠϦετ͕ͭ͘ωοτγϣοϐϯά 1. Ξϯέʔτʹ౴͑Δʂ 2. ࣗ୐ʹελΠϦετ with AI ͕બΜͩ঎඼͕ಧ͘ʂ 3. ؾʹೖͬͨ΋ͷΛߪೖʂଞ͸ฦ٫

Slide 5

Slide 5 text

DROBEͰͷAI׆༻ χοτ ΢ʔϧ λʔτϧωοΫ Ϩίϝϯσʔγϣϯ ίʔσΟωʔτఏҊ αΠζϚον λά෇͚ ͳͲͳͲ

Slide 6

Slide 6 text

DROBEͰͷAI׆༻ χοτ ΢ʔϧ λʔτϧωοΫ Ϩίϝϯσʔγϣϯ ίʔσΟωʔτఏҊ αΠζϚον λά෇͚ ͳͲͳͲ Made ofɹɹ

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

AGENDA 1. Symfonyͷಛ௃ 2. SymfonyͰͷޮ཰తͳ։ൃ 3. Symfonyͷ׆༻γʔϯ

Slide 9

Slide 9 text

λʔήοτͱΰʔϧ SymfonyͷՄೳੑͱ׆༻ʹ͍ͭͯ஌Δ ଞͷϑϨʔϜϫʔΫར༻ऀ

Slide 10

Slide 10 text

Symfonyͷಛ௃

Slide 11

Slide 11 text

Simple

Slide 12

Slide 12 text

Symfony: 4ͭͷ֓೦ 1. Components 2. Framework 3. Community 4. Philosophy 200Ҏ্ͷίϯϙʔωϯτ܈ ίϯϙʔωϯτΛར༻ͨ͠ϑϨʔϜϫʔΫ ͦΕΒΛࢧ͑ΔίϛϡχςΟ SymfonyΛଅਐ͢ΔϚΠϯυ

Slide 13

Slide 13 text

ϑϨʔϜϫʔΫ͸”ίϯϙʔωϯτ”ͷ͋ͭ·Γ composer create-project symfony/skeleton hoge symfony/console symfony/dotenv symfony/framework-bundle symfony/runtime symfony/yaml symfony/cache symfony/con fi g symfony/dependency-injection symfony/error-handler symfony/event-dispatcher symfony/http-foundation symfony/http-kernel symfony/poly fi ll-mbstring symfony/ fi lesystem symfony/ fi nder symfony/routing

Slide 14

Slide 14 text

ϑϨʔϜϫʔΫ͸”ίϯϙʔωϯτ”ͷ͋ͭ·Γ ίϯιʔϧ .env ϑϨʔϜϫʔΫ ϥϯλΠϜ YAMLύʔα Ωϟογϡ੍ޚ ίϯϑΟά DI Τϥʔ੍ޚ Πϕϯτ HTTP੍ޚ HTTPΧʔωϧ mbstring֦ு ϑΝΠϧ੍ޚ σΟϨΫτϦ੍ޚ ϧʔςΟϯά composer create-project symfony/skeleton hoge

Slide 15

Slide 15 text

Πϯετʔϧ௚ޙʹͰ͖Δ͜ͱ͸࠷খݶ -BSBWFM $BLF1)1 4ZNGPOZ $PNNBOE ˓ ˓ ˓ 3PVUJOH ˓ ˓ ˓ +40/ ˓ ˓ ˓ 5FNQMBUF ˓ ˓ º %# ˓ ˓ º 7BMJEBUJPO ˓ ˓ º .BJM ˓ ˓ º "VUI ˓ ˓ º &WFOU ˓ ˓ ˓ +PC ˓ ˓ º 5FTU ˓ ˓ º

Slide 16

Slide 16 text

ඞཁͳ࣌ʹඞཁͳ͚ͩ

Slide 17

Slide 17 text

ඞཁͳͱ͖ʹඞཁͳίϯϙʔωϯτΛΠϯετʔϧ composer require orm DB͕࢖͍͍ͨͳΒ ೝূ͍ͨ͠ͳΒ composer require security HTMLςϯϓϨʔτ࢖͍͍ͨ composer require twig ςετ͍ͨ͠ composer require test —dev

Slide 18

Slide 18 text

composer require orm

Slide 19

Slide 19 text

Symfony Flex: ίϯϙʔωϯτͷΠϯετʔϧϔϧύ Symfony͕༻ҙͨ͠ɺίϯϙʔωϯτʹ - ඞཁͳϥΠϒϥϦ - ઃఆϑΝΠϧͷ࡞੒ - Πϯετʔϧͷޙॲཧ Λ·ͱΊͨϨγϐΛݩʹΠϯετʔϧΛߦ͏ composerϓϥάΠϯ

Slide 20

Slide 20 text

ඞཁͳ࣌ʹඞཁͳ͚ͩ ίʔυ΋

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Autowiring: ґଘΦϒδΣΫτͷࣗಈ஫ೖ ಛఆͷσΟϨΫτϦͷΫϥεΛࣗಈೝࣝ͠ - ίϯετϥΫλ - ControllerͷΞΫγϣϯϝιου - Setter ͷҾ਺ʹࢦఆͨ͠ɺ ΫϥεɾΠϯλʔϑΣΠεΛܕʹ࣋ͭ ΦϒδΣΫτΛࣗಈͰ஫ೖ͢Δ ※૊ΈࠐΈܕ΋Ұ෦ՄೳʹͳΓ·ͨ͠

Slide 24

Slide 24 text

ΠϯλʔϑΣΠεࣗಈ஫ೖ̍ InterfaceΛ࣮૷ͨ͠ΫϥεΛࣗಈ஫ೖ

Slide 25

Slide 25 text

ΠϯλʔϑΣΠεࣗಈ஫ೖ̎ 1ͭΫϥεͰ2ͭͷΠϯλʔϑΣΠεΛ࣮૷

Slide 26

Slide 26 text

ΠϯλʔϑΣΠεࣗಈ஫ೖ̎ ͦΕͧΕʹࣗಈ஫ೖ

Slide 27

Slide 27 text

Symfonyͷಛ௃ 1. ඞཁͳ࣌ʹඞཁͳ΋ͷ͚ͩΛ࢖͏γϯϓϧͳߏ଄ 2. ඞཁͳ΋ͷΛ·ͱΊͯΠϯετʔϧɾઃఆͰ͖Δ؀ڥ 3. ґଘΛ੾ΓऔΓɾ஫ೖͰ͖Δखܰ͞ ඞཁ࠷௿ݶͳ΋ͷΛखܰʹѻ͑Δ

Slide 28

Slide 28 text

SymfonyͰͷޮ཰తͳ։ൃ

Slide 29

Slide 29 text

Loose

Slide 30

Slide 30 text

Symfony CLI: ։ൃʙσϓϩΠ·ͰΛॿ͚ΔCLI Go੡ͷCLIͰ - SymfonyϓϩδΣΫτͷ࡞੒ - ։ൃ؀ڥͷ੔උ - Platform.sh΁ͷσϓϩΠ ػೳΛ࣋ͬͨSymfonyҎ֎Ͱ΋࢖͑Δπʔϧ brew install symfony-cli/tap/symfony-cli

Slide 31

Slide 31 text

Α͘࢖͏ίϚϯυ symfony new project-name ϓϩδΣΫτ࡞੒ composer symfony composer ίϚϯυ ϩʔΧϧαʔόىಈ symfony {server:start -d | server:stop} PHP࣮ߦ symfony php ϓϩάϥϜ໊

Slide 32

Slide 32 text

PHPͷόʔδϣϯࢦఆ͕Մೳ ˞ར༻͍ͨ͠όʔδϣϯͷ1)1ΛΠϯετʔϧ͍ͯ͠Δඞཁ͕͋Γ·͢

Slide 33

Slide 33 text

࣮ߦதDocker͔Β؀ڥม਺Λ௥Ճ DATABASE_URL=“postgresql://app:[email protected]:85432/app?serverVersion=15&charset=utf8

Slide 34

Slide 34 text

Attributes: PHPʹຒΊࠐΉઃఆ৘ใ ίʔυએݴ࣌ʹຒΊࠐΉ͜ͱͰ ΞϓϦέʔγϣϯʹઃఆ৘ใΛ ࣋ͨͤΔ͜ͱ͕Ͱ͖ΔɺPHPͷػೳ ϑϨʔϜϫʔΫͰར༻͍ͯ͠Δ΋ͷ͸ Symfony, Spiral Framework

Slide 35

Slide 35 text

ϧʔςΟϯά ϦΫΤετͷϚοϐϯά

Slide 36

Slide 36 text

όϦσʔγϣϯ σʔλϚοϐϯά

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

࣮૷ίʔυ੹຿֎

Slide 39

Slide 39 text

Doctrine: DBΛѻ͏ORM DBΛѻ͏ORMͰ - POPOͳEntity - ࢀরΛओͱͨ͠Repository - DB΁ͷಉظΛ୲͏EntityManager Λ΋ͭɺDataMapperܕͷORM symfony composer require orm

Slide 40

Slide 40 text

DataMapperͱActiveRecordͷҧ͍ id=1 id=4 id=1 id=4 id=4 id=1 id=1 id=1 id=4 ࢀর ίϐʔ ૢ࡞ ૢ࡞ ϏδωεϩδοΫ ->save() -> f lush() ஗Ԇ ϑΣον Entity Manager ಉظ ->save() ->save() ίϯτϩʔϥʔ ΫΤϦ͝ͱʹҟͳΔΠϯελϯεੜ੒ɻ ΠϯελϯεʹҰҙੑ͕ͳ͍ɻ != Entity DB ࣮ମ͕ͳ͍ͱ੔߹ੑ͕੒Γཱͨͳ͍ɻ ϏδωεϩδοΫ͕ʮDBอଘʯ੹຿Λ࣋ͭɻ ͢΂ͯͷ Entity ͸Ծ૝తʹΦϯϝϞϦͰ ଍Γͳ͍΋ͷ͚ͩΛ஗ԆϑΣονɻ Repository ͸ࢀরΛఏڙ͢Δ͚ͩɻ ϏδωεϩδοΫ͸OOP͚ͩͰ׬݁͢Δɻ ࠩ෼SQLੜ੒

Slide 41

Slide 41 text

ར༻Repository ϑΟʔϧυఆٛ Getter/Setter AttributesΛղऍͯ͠ϚΠάϨʔγϣϯʢdiffʣ࡞੒

Slide 42

Slide 42 text

ϑΟʔϧυఆٛΛ΋ͱʹͨ͠ϚΠάϨʔγϣϯ

Slide 43

Slide 43 text

EntityManagerΛDI EntityManager΁ొ࿥ɾಉظ

Slide 44

Slide 44 text

EntityManager͕DI͞ΕͯΔՕॴ = DBಉظ͋Γ

Slide 45

Slide 45 text

঎඼࡞੒ DBಉظ ࡏݿ࡞੒ มߋཤྺ࡞੒ ϦΫΤετडऔ $POUSPMMFS 6TF$BTF &WFOU-JTUFOFS

Slide 46

Slide 46 text

঎඼࡞੒ DBಉظ ࡏݿ࡞੒ มߋཤྺ࡞੒ ϦΫΤετडऔ $POUSPMMFS 6TF$BTF &WFOU-JTUFOFS DBอଘͷ͜ͱΛߟ͑ͳͯ͘Α͍ྖҬ

Slide 47

Slide 47 text

ΦϒδΣΫτΛฦ͚ͩ͢ͷγϯϓϧͳΫϥεʹ

Slide 48

Slide 48 text

Test: ֤छςετΛαϙʔτ SymfonyͰ͸ - Unit Test - Integration Test - Application Test Λߦ͏؀ڥΛ༻ҙɻ·ͨɺSymfony PantherͰ E2Eςετ΋࣮ࢪՄೳɻ

Slide 49

Slide 49 text

DI෦෼ΛϞοΫ

Slide 50

Slide 50 text

zenstruck/foundry: ඞཁͳྔͷσʔλΛొ࿥ ςετΛߦ͏ࡍʹ - ඞཁͳྔͷσʔλͷొ࿥ - ϚΠάϨʔγϣϯʹґଘ͠ͳ͍ςʔϒϧ࡞੒ - ࢖͍ํ͸LaravelͷFactoryνοΫ Λ࣮ݱ͢Δɺσʔλొ࿥ϥΠϒϥϦ symfony composer require zenstruck/foundry

Slide 51

Slide 51 text

Ͱ͖Δςʔϒϧ͸’item’͚ͩ

Slide 52

Slide 52 text

Symfonyͷޮ཰తͳ։ൃ 1. ϩʔΧϧ + DockerͰͷ։ൃΛڧྗʹαϙʔτ 2. AttributesΛར༻ͨ͠ɺඞཁͳϩδοΫͷΈͷ։ൃ͕Մೳ 3. DIΛ༗ޮʹར༻ͨ͠ɺඞཁͳՕॴɾσʔλͷΈͷςετ ແҙࣝʹૄ݁߹ʹۙͮ͘։ൃମݧ

Slide 53

Slide 53 text

Symfonyͷ׆༻γʔϯ

Slide 54

Slide 54 text

Flexible

Slide 55

Slide 55 text

ϓϩτλΠϓɾMVP CLI, API, HTMLͳͲ৭ʑͳܗʹ༰қʹมߋ Ͱ͖ΔͨΊɺεςʔΫϗϧμʔͱ͢͹΍͘ ҙࢥૄ௨͕Մೳɻ ·ͨɺॳظஈ֊͔Βૄ݁߹Λอͪ΍͍͢ɻ

Slide 56

Slide 56 text

CRUD Router, Voter, ValueResolverͳͲͷ AttributesΛۦ࢖͢Δ͜ͱͰ༰қʹ CRUD͕࡞੒Ͱ͖Δ

Slide 57

Slide 57 text

ValueResolver ControllerͷΞΫγϣϯϝιουͰҾ਺ʹ ResolverΛࢦఆ͢Δ͜ͱͰɺ ඞཁͳσʔλͷϩδοΫΛController͔Β ഉআͰ͖Δ

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

؅ཧը໘ Role, VoterͳͲͷೝূػೳΛ࢖ͬͨ ϑϨΩγϒϧͳΞΫηε੍ޚ͕Մೳɻ Ճ͑ͯɺWork fl owʹΑΔεςʔλε؅ཧͷ ಋೖ͕͠΍͍͢ɻ ·ͨɺ؆୯ͳ؅ཧը໘Ͱ͋Ε͹ EasyAdmin Bundle΋͓͢͢Ί

Slide 60

Slide 60 text

Workflow ΦϒδΣΫτʹεςʔλεΛ༩͑ɺ εςʔλεͷ੾Γସ͑ɺঢ়ଶͷνΣοΫΛ ߦ͏ɻ symfony composer require work fl ow

Slide 61

Slide 61 text

εςʔλεछྨ τϥϯδογϣϯʢભҠʣ

Slide 62

Slide 62 text

τϥϯδογϣϯʢ֬ೝˍભҠʣ Work fl owΛDI

Slide 63

Slide 63 text

API ڧྗͳSerializerΛར༻͠ɺ ༰қʹAPIͷ։ൃ͕Մೳɻ ·ͨɺ؆୯ͳ΋ͷͰ͋Ε͹ API PlatformΛ࢖͑͹AttributesΛ଍͚ͩ͢Ͱ APIͷ࡞੒͕Մೳ

Slide 64

Slide 64 text

Serializer ΦϒδΣΫτ΍഑ྻɺJSONͳͲΛͦΕͧΕͷ ϑΥʔϚοτʹม׵͢Δ symfony composer require serializer

Slide 65

Slide 65 text

ࢦఆͨ͠άϧʔϓͷΈදࣔ ඇදࣔ

Slide 66

Slide 66 text

/api/itemsͷCRUDͳAPI͕ࣗಈੜ੒

Slide 67

Slide 67 text

ϞδϡϥϞϊϦε σΟϨΫτϦߏ଄ʹେ͖ͳറΓ͸ ͳ͍ͷͰɺυϝΠϯຖʹ੾Γग़ͯ͠ ϞδϡϥϞϊϦεՄೳɻଞͷखஈ΋͋Γɻ ৄ͘͠͸…

Slide 68

Slide 68 text

14:50ʙ τϥοΫ1

Slide 69

Slide 69 text

Symfonyͷ׆༻γʔϯ 1. ϓϩτλΠϓ͔ΒΤϯλʔϓϥΠζ·Ͱͦͭͳ͘͜ͳ͢ 2. ෳࡶͳॲཧΛ௥͍ग़͢͜ͱͰಘΔɺߴ͍ϝϯςφϏϦςΟ 3. (࣌ؒͷ౎߹Ͱઆ໌Ͱ͖ͳ͍) ࠷৽όʔδϣϯ௥ैͷ͠΍͢͞ ॊೈͰڧਟͳαʔϏεͷߏங͕Մೳ

Slide 70

Slide 70 text

We are hiring!! ΧδϡΞϧ໘ஊਵ࣌ड෇தͰ͢ʂ DROBE͸͍͍ͧ ࠓͳΒ৭ʑͳτϥΠΛମݧͰ͖·͢

Slide 71

Slide 71 text

No content