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
PHPでURLルーティングを自作する
Search
bmf_san
June 29, 2019
Programming
1
2.8k
PHPでURLルーティングを自作する
bmf_san
June 29, 2019
Tweet
Share
More Decks by bmf_san
See All by bmf_san
契約テストとPactについて
bmf_san
0
41
5分でわかるSLO
bmf_san
2
60
権限について考える
bmf_san
2
72
自作HTTPルーターから新しいServeMuxへ
bmf_san
3
1.6k
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
270
アジャイルワークショップ
bmf_san
0
100
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
2.4k
天下一HTTPRouter武闘会.pdf
bmf_san
8
4.3k
ゆっくりHackerRank
bmf_san
0
110
Other Decks in Programming
See All in Programming
事業成長を爆速で進めてきたプロダクトエンジニアたちの成功談・失敗談
nealle
3
1.4k
たのしいparse.y
ydah
3
120
42 best practices for Symfony, a decade later
tucksaun
1
180
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
From Translations to Multi Dimension Entities
alexanderschranz
2
130
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Haze - Real time background blurring
chrisbanes
1
500
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
630
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
94
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Facilitating Awesome Meetings
lara
50
6.1k
What's in a price? How to price your products and services
michaelherold
243
12k
The Pragmatic Product Professional
lauravandoore
32
6.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
A Philosophy of Restraint
colly
203
16k
Transcript
PHPͰURLϧʔςΟϯάΛࣗ࡞͢Δ @bmf_san @PHP Conference Fukuoka 2019 2019/06/29
@bmf_san bmf-san bmf-tech.com Twitter Github Blog
֓ཁ 1. ಈػ • ϧʔςΟϯάΛࣗ࡞͠Α͏ͱࢥ͖͔͚ͬͨͬ 2. Ͳ͏࡞͔ͬͨʁ • ࣮աఔʹ͍ͭͯ 3.
·ͱΊ
1 ಈػ
ಈػ • ݩʑGolangͰ࣮͍ͨ͠ͱߟ͍͑ͯͨ • ͱΓ͋͑ͣ׳Ε͍ͯΔPHP͔Βɾɾ • ͳΜ͔ࣗ࡞ͯ͠ΈͨΒ໘നͦ͏ʢখฒײʣ
2 Ͳ͏࡞͔ͬͨʁ
࣮ࡍʹ࡞ͬͨͷ
ιʔε • Github • bmf-san/ahi-router • https://github.com/bmf-san/ahi-router
ϧʔςΟϯάΛఆٛ͢Δ ୳ࡧ݁ՌΛಘΔ ࠓճ࣮ͨ͠3PVUFSύοέʔδ
ΞΫγϣϯͱύεύϥϝʔλ͕औಘͰ͖Δ
ύοέʔδެ։ • Packagist • bmf-san/ahi-router • https://packagist.org/packages/bmf-san/ahi- router#2.0.0
࣮աఔ
࣮աఔͷ • URLϧʔςΟϯάͱԿ͔ʢཁ݅ఆٛʣ • ༷ΛܾΊΔ • ઃܭ • σʔλߏΛߟ͑Δ •
࣮
URLϧʔςΟϯάͱԿ͔
URLϧʔςΟϯάͱ • ϦΫΤετ͞ΕͨURLʹରͯ͠ɺ࣮ߦ͍ͨ͠ॲཧΛฦ͢ • ύεʢ/foo/bar/1ʣ෦Λύʔεͯ͠ɺҙͷΛฦ͢ • ਖ਼نදݱ • จࣈྻ୳ࡧΞϧΰϦζϜ
URLϧʔςΟϯάͱ IUUQFYBNQMFDPNGPPCBS GPPCBS JE͕ BDUJPO #BS$POUSPMMFS!TIPX 3PVUFS ϧʔςΟϯάॲཧΛߦ͏ *OQVU 0VUQVU
༷ΛܾΊΔ
༷ • ෳͷύεύϥϝʔλʔΛؚΉURLʹରԠ • /foo/bar/:foo/:bar • ΞΫγϣϯͱύϥϝʔλʔใΛฦ͢ • ϜζΧγΠίτϋϠϥφΠ •
ଟػೳ • ϋΠύϑΥʔϚϯε
σʔλߏΛߟ͑Δ
σʔλߏΛߟ͑Δ IUUQFYBNQMFDPNGPPCBS GPPCBS JE͕ BDUJPO #BS$POUSPMMFS!TIPX 3PVUFS *OQVU 0VUQVU
I/O Input • Path • /foo/bar/1 • HTTP Method •
GET/POST… Output • Action • ॲཧ • ex. PostController@getPosts • Parameters • ύεύϥϝʔλʔ • ex. /boo/bar/:id
Routing Map *OQVU 0VUQVU 3PVUFS 1BUI )551.FUIPE "DUJPO 1BSBNFUFST 3PVUJOH.BQ
ϧʔλʔ͕෦Ͱ࣋ͭ σʔλߏ
Routing Mapͱ • Routing Map • ϧʔςΟϯάͷͨΊͷσʔλߏ • Router͕෦తʹ࣋ͭ •
ϧʔςΟϯάͷఆ͔ٛΒੜ͞ΕΔ • URLͱ࣮ߦ͍ͨ͠ॲཧΛϚοϐϯά
Routing 1BUI .FUIPE "DUJPO (&5 *OEFY$POUSPMMFS!JOEFY QPTUT (&5 1PTU$POUSPMMFS!HFU1PTUT
QPTUTJE (&5 1PTU$POUSPMMFS!FEJU QPTUTJE 1045 1PTU$POUSPMMFS!VQEBUF QPTUTJEUPLFO (&5 1PTU$POUSPMMFS!QSFWJFX QPTUTDBUFHPSZ (&5 1PTU$POUSPMMFS!HFU1PTUT#Z$BUFHPSZ QSPpMF (&5 1S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&/%@10*/5 &/%@10* /5 QSPpMF DBUFHPSZ &/%@10*/5
QPTUT JE &/%@10*/5 (&5QPTUT
UPLFO &/%@10*/5 &/%@10*/5 &/%@10*/5 &/%@10* /5 QSPpMF DBUFHPSZ &/%@10*/5
QPTUT JE &/%@10*/5 (&5QPTUT (&51PTU$POUSPMMFS!HFU1PTUT 10451PTU$POUSPMMFS!FEJU )551ϝιουʹԠͯ͡ॲཧΛৼΓ͚ ˞QBSBNFUFSTҰॹʹฦ͢
UPLFO &/%@10*/5 &/%@10*/5 &/%@10*/5 &/%@10*/5 QSPpMF DBUFHPSZ &/%@10*/5 QPTUT
JE &/%@10*/5
࣮
࣮
Routerͷ࣮ • ͲΜͳॲཧ͕ඞཁ͔ʁ • Routing MapΛੜ͢Δ • Routing Map͔Β୳ࡧ͢Δ
ϧʔςΟϯάϚοϓΛੜ • ϧʔςΟϯάϚοϓΛੜ͢Δ • PathɺHTTP MethodɺActionͷσʔληοτ͔Βੜ • /posts GET PostController@getPosts
ϧʔςΟϯάΛఆٛ͢Δ
࣮
ࢀরʢʣͰ͕ΜΔ
ϧʔςΟϯάϚοϓ͔Β୳ࡧ • ϧʔςΟϯάϚοϓ͔Β୳ࡧ͢Δ • ଟ࣍ݩྻΛ୳ࡧ͢Δॲཧ • →ߏͷ୳ࡧΞϧΰϦζϜ
None
՝ • ΤϥʔϋϯυϦϯά • ࣮ӡ༻ʹ͚ͨػೳ։ൃ • ϛυϧΣΞͷͭͳ͗ࠐΈ • ύεύϥϝʔλʹਖ਼نදݱ͕͑Δ •
ͦͷଞศརػೳͱ͔ • ࣮ߦͷߟྀ • ߏɺจࣈྻ୳ࡧΞϧΰϦζϜ
3 ·ͱΊ
·ͱΊ • ָ͍͠ • ࠶ؼॲཧࢀরʢ&ʣΛ͏ྑ͍࿅शʹͳͬͨ • ΞϧΰϦζϜΛֶͿ͖͔͚ͬʹͳͬͨ • ΑΓྑ͍ઃܭɺύϑΥʔϚϯεΛࢦ͢
ιʔε • Github • bmf-san/bmf-router • https://github.com/bmf-san/bmf-router
Thank you !