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.7k
PHPでURLルーティングを自作する
bmf_san
June 29, 2019
Tweet
Share
More Decks by bmf_san
See All by bmf_san
契約テストとPactについて
bmf_san
0
38
5分でわかるSLO
bmf_san
2
55
権限について考える
bmf_san
2
67
自作HTTPルーターから新しいServeMuxへ
bmf_san
3
1.6k
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
260
アジャイルワークショップ
bmf_san
0
94
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
2.3k
天下一HTTPRouter武闘会.pdf
bmf_san
8
4.2k
ゆっくりHackerRank
bmf_san
0
110
Other Decks in Programming
See All in Programming
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Outline View in SwiftUI
1024jp
1
330
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
CSC509 Lecture 12
javiergs
PRO
0
160
Featured
See All Featured
Navigating Team Friction
lara
183
14k
Designing Experiences People Love
moore
138
23k
How to Ace a Technical Interview
jacobian
276
23k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Visualization
eitanlees
145
15k
4 Signs Your Business is Dying
shpigford
180
21k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The Language of Interfaces
destraynor
154
24k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
We Have a Design System, Now What?
morganepeng
50
7.2k
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 1SPpMF$POU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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 !