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.4k
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
49
AIで生成したものをAIでチェックしてる話
ippey
0
1.9k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
660
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.2k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.3k
それぞれの特徴から考えるフレームワーク選び
ippey
1
860
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
はじめてのCI - 実践編 -
ippey
1
280
Other Decks in Programming
See All in Programming
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Jakarta EE meets AI
ivargrimstad
0
590
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
Quine, Polyglot, 良いコード
qnighy
4
650
距離関数を極める! / SESSIONS 2024
gam0022
0
290
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Jakarta EE meets AI
ivargrimstad
0
120
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Adopting Sorbet at Scale
ufuk
73
9.1k
Teambox: Starting and Learning
jrom
133
8.8k
A designer walks into a library…
pauljervisheath
204
24k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
420
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Building Applications with DynamoDB
mza
90
6.1k
Typedesign – Prime Four
hannesfritz
40
2.4k
The Invisible Side of Design
smashingmag
298
50k
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