Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
57
AIで生成したものをAIでチェックしてる話
ippey
0
1.9k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
680
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.2k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.3k
それぞれの特徴から考えるフレームワーク選び
ippey
1
870
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
はじめてのCI - 実践編 -
ippey
1
290
Other Decks in Programming
See All in Programming
新規学習のハードルを下げる方法とは?/ How to Make Learning Something New Easier?
nobuoooo
1
130
Jakarta EE meets AI
ivargrimstad
0
870
Functional Event Sourcing using Sekiban
tomohisa
0
130
Cognitoが大型アップデート!Managed Loginとパスワードレスログインを実際に使ってみた@しむそくRadio Special Day1
tmhirai
3
240
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
150
Arm移行タイムアタック
qnighy
0
410
HTTP compression in PHP and Symfony apps
dunglas
2
1.4k
コンテンツの主権を守るため(?)、高機能画像CDNからAWS自前対応に乗り換えた話
lengthtail
1
120
flutterkaigi_2024.pdf
kyoheig3
0
460
Discord Bot with AI -for English learners-
xin9le
1
110
PaaSとSaaSの境目で信頼性と開発速度を両立する 〜TROCCO®︎のこれまでとこれから〜
gtnao
6
7k
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
630
Featured
See All Featured
Writing Fast Ruby
sferik
627
61k
Code Reviewing Like a Champion
maltzj
520
39k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Producing Creativity
orderedlist
PRO
341
39k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Scaling GitHub
holman
458
140k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Automating Front-end Workflow
addyosmani
1366
200k
GitHub's CSS Performance
jonrohan
1030
460k
How to Ace a Technical Interview
jacobian
276
23k
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