Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
25分で理解する!Symfonyの魅力とその実践的活用法
Search
Ippei Sumida
October 08, 2023
Programming
1
6.5k
25分で理解する!Symfonyの魅力とその実践的活用法
PHP Conference Japan 2023でお話ししたスライドです。 #phpcon #phpcon2023
Ippei Sumida
October 08, 2023
Tweet
Share
More Decks by Ippei Sumida
See All by Ippei Sumida
みんなでQAしてる話
ippey
0
59
AIで生成したものをAIでチェックしてる話
ippey
0
2k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
690
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.3k
それぞれの特徴から考えるフレームワーク選び
ippey
1
880
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
はじめてのCI - 実践編 -
ippey
1
290
Other Decks in Programming
See All in Programming
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
170
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
450
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
350
선언형 UI에서의 상태관리
l2hyunwoo
0
140
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
200
Criando Commits Incríveis no Git
marcelgsantos
2
170
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
630
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
940
From Translations to Multi Dimension Entities
alexanderschranz
2
130
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Statistics for Hackers
jakevdp
796
220k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Speed Design
sergeychernyshev
25
670
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Code Review Best Practice
trishagee
65
17k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Adopting Sorbet at Scale
ufuk
73
9.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Typedesign – Prime Four
hannesfritz
40
2.4k
Transcript
25Ͱཧղ͢Δʂ Symfonyͷັྗͱͦͷ࣮ફత׆༻๏ PHP Conference Japan 2023
• ֯ాɹҰฏ • גࣜձࣾDROBE • Kansai Symfony Meetup • CoderDojo
ຕํ ࣗݾհ
DROBEͷհ
ελΠϦετ͕ͭ͘ωοτγϣοϐϯά 1. Ξϯέʔτʹ͑Δʂ 2. ࣗʹελΠϦετ with AI ͕બΜ͕ͩಧ͘ʂ 3. ؾʹೖͬͨͷΛߪೖʂଞฦ٫
DROBEͰͷAI׆༻ χοτ ʔϧ λʔτϧωοΫ Ϩίϝϯσʔγϣϯ ίʔσΟωʔτఏҊ αΠζϚον λά͚ ͳͲͳͲ
DROBEͰͷAI׆༻ χοτ ʔϧ λʔτϧωοΫ Ϩίϝϯσʔγϣϯ ίʔσΟωʔτఏҊ αΠζϚον λά͚ ͳͲͳͲ Made
ofɹɹ
None
AGENDA 1. Symfonyͷಛ 2. SymfonyͰͷޮతͳ։ൃ 3. Symfonyͷ׆༻γʔϯ
λʔήοτͱΰʔϧ SymfonyͷՄೳੑͱ׆༻ʹ͍ͭͯΔ ଞͷϑϨʔϜϫʔΫར༻ऀ
Symfonyͷಛ
Simple
Symfony: 4ͭͷ֓೦ 1. Components 2. Framework 3. Community 4. Philosophy
200Ҏ্ͷίϯϙʔωϯτ܈ ίϯϙʔωϯτΛར༻ͨ͠ϑϨʔϜϫʔΫ ͦΕΒΛࢧ͑ΔίϛϡχςΟ SymfonyΛଅਐ͢ΔϚΠϯυ
ϑϨʔϜϫʔΫ”ίϯϙʔωϯτ”ͷ͋ͭ·Γ 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
ϑϨʔϜϫʔΫ”ίϯϙʔωϯτ”ͷ͋ͭ·Γ ίϯιʔϧ .env ϑϨʔϜϫʔΫ ϥϯλΠϜ YAMLύʔα Ωϟογϡ੍ޚ ίϯϑΟά DI Τϥʔ੍ޚ
Πϕϯτ HTTP੍ޚ HTTPΧʔωϧ mbstring֦ு ϑΝΠϧ੍ޚ σΟϨΫτϦ੍ޚ ϧʔςΟϯά composer create-project symfony/skeleton hoge
ΠϯετʔϧޙʹͰ͖Δ͜ͱ࠷খݶ -BSBWFM $BLF1)1 4ZNGPOZ $PNNBOE ˓ ˓ ˓ 3PVUJOH ˓
˓ ˓ +40/ ˓ ˓ ˓ 5FNQMBUF ˓ ˓ º %# ˓ ˓ º 7BMJEBUJPO ˓ ˓ º .BJM ˓ ˓ º "VUI ˓ ˓ º &WFOU ˓ ˓ ˓ +PC ˓ ˓ º 5FTU ˓ ˓ º
ඞཁͳ࣌ʹඞཁͳ͚ͩ
ඞཁͳͱ͖ʹඞཁͳίϯϙʔωϯτΛΠϯετʔϧ composer require orm DB͕͍͍ͨͳΒ ೝূ͍ͨ͠ͳΒ composer require security HTMLςϯϓϨʔτ͍͍ͨ
composer require twig ςετ͍ͨ͠ composer require test —dev
composer require orm
Symfony Flex: ίϯϙʔωϯτͷΠϯετʔϧϔϧύ Symfony͕༻ҙͨ͠ɺίϯϙʔωϯτʹ - ඞཁͳϥΠϒϥϦ - ઃఆϑΝΠϧͷ࡞ - Πϯετʔϧͷޙॲཧ
Λ·ͱΊͨϨγϐΛݩʹΠϯετʔϧΛߦ͏ composerϓϥάΠϯ
ඞཁͳ࣌ʹඞཁͳ͚ͩ ίʔυ
None
None
Autowiring: ґଘΦϒδΣΫτͷࣗಈೖ ಛఆͷσΟϨΫτϦͷΫϥεΛࣗಈೝࣝ͠ - ίϯετϥΫλ - ControllerͷΞΫγϣϯϝιου - Setter ͷҾʹࢦఆͨ͠ɺ
ΫϥεɾΠϯλʔϑΣΠεΛܕʹ࣋ͭ ΦϒδΣΫτΛࣗಈͰೖ͢Δ ※ΈࠐΈܕҰ෦ՄೳʹͳΓ·ͨ͠
ΠϯλʔϑΣΠεࣗಈೖ̍ InterfaceΛ࣮ͨ͠ΫϥεΛࣗಈೖ
ΠϯλʔϑΣΠεࣗಈೖ̎ 1ͭΫϥεͰ2ͭͷΠϯλʔϑΣΠεΛ࣮
ΠϯλʔϑΣΠεࣗಈೖ̎ ͦΕͧΕʹࣗಈೖ
Symfonyͷಛ 1. ඞཁͳ࣌ʹඞཁͳͷ͚ͩΛ͏γϯϓϧͳߏ 2. ඞཁͳͷΛ·ͱΊͯΠϯετʔϧɾઃఆͰ͖Δڥ 3. ґଘΛΓऔΓɾೖͰ͖Δखܰ͞ ඞཁ࠷ݶͳͷΛखܰʹѻ͑Δ
SymfonyͰͷޮతͳ։ൃ
Loose
Symfony CLI: ։ൃʙσϓϩΠ·ͰΛॿ͚ΔCLI GoͷCLIͰ - SymfonyϓϩδΣΫτͷ࡞ - ։ൃڥͷඋ - Platform.shͷσϓϩΠ
ػೳΛ࣋ͬͨSymfonyҎ֎Ͱ͑Δπʔϧ brew install symfony-cli/tap/symfony-cli
Α͘͏ίϚϯυ symfony new project-name ϓϩδΣΫτ࡞ composer symfony composer ίϚϯυ ϩʔΧϧαʔόىಈ
symfony {server:start -d | server:stop} PHP࣮ߦ symfony php ϓϩάϥϜ໊
PHPͷόʔδϣϯࢦఆ͕Մೳ ˞ར༻͍ͨ͠όʔδϣϯͷ1)1ΛΠϯετʔϧ͍ͯ͠Δඞཁ͕͋Γ·͢
࣮ߦதDocker͔ΒڥมΛՃ DATABASE_URL=“postgresql://app:
[email protected]
:85432/app?serverVersion=15&charset=utf8
Attributes: PHPʹຒΊࠐΉઃఆใ ίʔυએݴ࣌ʹຒΊࠐΉ͜ͱͰ ΞϓϦέʔγϣϯʹઃఆใΛ ࣋ͨͤΔ͜ͱ͕Ͱ͖ΔɺPHPͷػೳ ϑϨʔϜϫʔΫͰར༻͍ͯ͠Δͷ Symfony, Spiral Framework
ϧʔςΟϯά ϦΫΤετͷϚοϐϯά
όϦσʔγϣϯ σʔλϚοϐϯά
None
࣮ίʔυ֎
Doctrine: DBΛѻ͏ORM DBΛѻ͏ORMͰ - POPOͳEntity - ࢀরΛओͱͨ͠Repository - DBͷಉظΛ୲͏EntityManager ΛͭɺDataMapperܕͷORM
symfony composer require orm
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ੜ
ར༻Repository ϑΟʔϧυఆٛ Getter/Setter AttributesΛղऍͯ͠ϚΠάϨʔγϣϯʢdiffʣ࡞
ϑΟʔϧυఆٛΛͱʹͨ͠ϚΠάϨʔγϣϯ
EntityManagerΛDI EntityManagerొɾಉظ
EntityManager͕DI͞ΕͯΔՕॴ = DBಉظ͋Γ
࡞ DBಉظ ࡏݿ࡞ มߋཤྺ࡞ ϦΫΤετडऔ $POUSPMMFS 6TF$BTF &WFOU-JTUFOFS
࡞ DBಉظ ࡏݿ࡞ มߋཤྺ࡞ ϦΫΤετडऔ $POUSPMMFS 6TF$BTF &WFOU-JTUFOFS DBอଘͷ͜ͱΛߟ͑ͳͯ͘Α͍ྖҬ
ΦϒδΣΫτΛฦ͚ͩ͢ͷγϯϓϧͳΫϥεʹ
Test: ֤छςετΛαϙʔτ SymfonyͰ - Unit Test - Integration Test -
Application Test Λߦ͏ڥΛ༻ҙɻ·ͨɺSymfony PantherͰ E2Eςετ࣮ࢪՄೳɻ
DI෦ΛϞοΫ
zenstruck/foundry: ඞཁͳྔͷσʔλΛొ ςετΛߦ͏ࡍʹ - ඞཁͳྔͷσʔλͷొ - ϚΠάϨʔγϣϯʹґଘ͠ͳ͍ςʔϒϧ࡞ - ͍ํLaravelͷFactoryνοΫ Λ࣮ݱ͢ΔɺσʔλొϥΠϒϥϦ
symfony composer require zenstruck/foundry
Ͱ͖Δςʔϒϧ’item’͚ͩ
Symfonyͷޮతͳ։ൃ 1. ϩʔΧϧ + DockerͰͷ։ൃΛڧྗʹαϙʔτ 2. AttributesΛར༻ͨ͠ɺඞཁͳϩδοΫͷΈͷ։ൃ͕Մೳ 3. DIΛ༗ޮʹར༻ͨ͠ɺඞཁͳՕॴɾσʔλͷΈͷςετ ແҙࣝʹૄ݁߹ʹۙͮ͘։ൃମݧ
Symfonyͷ׆༻γʔϯ
Flexible
ϓϩτλΠϓɾMVP CLI, API, HTMLͳͲ৭ʑͳܗʹ༰қʹมߋ Ͱ͖ΔͨΊɺεςʔΫϗϧμʔͱ͘͢ ҙࢥૄ௨͕Մೳɻ ·ͨɺॳظஈ֊͔Βૄ݁߹Λอ͍ͪ͢ɻ
CRUD Router, Voter, ValueResolverͳͲͷ AttributesΛۦ͢Δ͜ͱͰ༰қʹ CRUD͕࡞Ͱ͖Δ
ValueResolver ControllerͷΞΫγϣϯϝιουͰҾʹ ResolverΛࢦఆ͢Δ͜ͱͰɺ ඞཁͳσʔλͷϩδοΫΛController͔Β ഉআͰ͖Δ
None
ཧը໘ Role, VoterͳͲͷೝূػೳΛͬͨ ϑϨΩγϒϧͳΞΫηε੍ޚ͕Մೳɻ Ճ͑ͯɺWork fl owʹΑΔεςʔλεཧͷ ಋೖ͕͍͢͠ɻ ·ͨɺ؆୯ͳཧը໘Ͱ͋Ε EasyAdmin
Bundle͓͢͢Ί
Workflow ΦϒδΣΫτʹεςʔλεΛ༩͑ɺ εςʔλεͷΓସ͑ɺঢ়ଶͷνΣοΫΛ ߦ͏ɻ symfony composer require work fl ow
εςʔλεछྨ τϥϯδογϣϯʢભҠʣ
τϥϯδογϣϯʢ֬ೝˍભҠʣ Work fl owΛDI
API ڧྗͳSerializerΛར༻͠ɺ ༰қʹAPIͷ։ൃ͕Մೳɻ ·ͨɺ؆୯ͳͷͰ͋Ε API PlatformΛ͑AttributesΛ͚ͩ͢Ͱ APIͷ࡞͕Մೳ
Serializer ΦϒδΣΫτྻɺJSONͳͲΛͦΕͧΕͷ ϑΥʔϚοτʹม͢Δ symfony composer require serializer
ࢦఆͨ͠άϧʔϓͷΈදࣔ ඇදࣔ
/api/itemsͷCRUDͳAPI͕ࣗಈੜ
ϞδϡϥϞϊϦε σΟϨΫτϦߏʹେ͖ͳറΓ ͳ͍ͷͰɺυϝΠϯຖʹΓग़ͯ͠ ϞδϡϥϞϊϦεՄೳɻଞͷखஈ͋Γɻ ৄ͘͠…
14:50ʙ τϥοΫ1
Symfonyͷ׆༻γʔϯ 1. ϓϩτλΠϓ͔ΒΤϯλʔϓϥΠζ·Ͱͦͭͳ͘͜ͳ͢ 2. ෳࡶͳॲཧΛ͍ग़͢͜ͱͰಘΔɺߴ͍ϝϯςφϏϦςΟ 3. (࣌ؒͷ߹Ͱઆ໌Ͱ͖ͳ͍) ࠷৽όʔδϣϯैͷ͢͠͞ ॊೈͰڧਟͳαʔϏεͷߏங͕Մೳ
We are hiring!! ΧδϡΞϧ໘ஊਵ࣌डதͰ͢ʂ DROBE͍͍ͧ ࠓͳΒ৭ʑͳτϥΠΛମݧͰ͖·͢
None