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.4k
それぞれの特徴から考えるフレームワーク選び
ippey
1
880
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
はじめてのCI - 実践編 -
ippey
1
290
Other Decks in Programming
See All in Programming
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
200
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
Symfony Mapper Component
soyuka
2
730
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
선언형 UI에서의 상태관리
l2hyunwoo
0
170
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
370
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
useSyncExternalStoreを使いまくる
ssssota
6
1.1k
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
790
103 Early Hints
sugi_0000
1
230
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
A better future with KSS
kneath
238
17k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Gamification - CAS2011
davidbonilla
80
5.1k
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