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
Ethereum_.pdf
nekomatu
0
460
みんなでプロポーザルを書いてみた
yuriko1211
0
260
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Happy Clients
brianwarren
98
6.7k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Embracing the Ebb and Flow
colly
84
4.5k
How GitHub (no longer) Works
holman
310
140k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Being A Developer After 40
akosma
86
590k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
A designer walks into a library…
pauljervisheath
203
24k
Designing for humans not robots
tammielis
250
25k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
The World Runs on Bad Software
bkeepers
PRO
65
11k
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