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のmiddlewareを 使いこなすために
Search
YAMAOKA Hiroyuki
January 26, 2019
Technology
3
2.3k
PHPのmiddlewareを 使いこなすために
PHPカンファレンス仙台2019での発表資料です。
https://phpcon-sendai.net/2019/
YAMAOKA Hiroyuki
January 26, 2019
Tweet
Share
More Decks by YAMAOKA Hiroyuki
See All by YAMAOKA Hiroyuki
エンジニアの「センス」とは何か / What is the sense of engineers
hiro_y
19
8.4k
CSRF対策のやり方、そろそろアップデートしませんか / Update your knowledge of CSRF protection
hiro_y
29
23k
PHPで任意精度演算を行って「正しい」金額計算をする方法 / Perform arbitrary precision arithmetic in PHP to achieve "accurate" monetary calculations
hiro_y
2
2.6k
PHPのバージョンアップ実際のところどうなの? / How actually upgrade of PHP is
hiro_y
3
720
PHPのDI、attributesとこれから / PHP DI with attributes
hiro_y
1
2.1k
PHPのアノテーションの仕組みとメリット・デメリット / About PHP annotations
hiro_y
1
8.2k
株式会社 USEN Media - PHPカンファレンス北海道2019 / 2019-09-21_phpcondo-2019_usen-media
hiro_y
0
200
Slim Frameworkで始めるPHPのmiddleware
hiro_y
4
2.1k
Node.jsやPHPでも こわくないHeroku
hiro_y
1
1.5k
Other Decks in Technology
See All in Technology
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
【若手エンジニア応援LT会】ソフトウェアを学んできた私がインフラエンジニアを目指した理由
kazushi_ohata
0
150
Application Development WG Intro at AppDeveloperCon
salaboy
0
190
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
TypeScript、上達の瞬間
sadnessojisan
46
13k
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
300
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
フルカイテン株式会社 採用資料
fullkaiten
0
40k
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
GitHub's CSS Performance
jonrohan
1030
460k
How STYLIGHT went responsive
nonsquared
95
5.2k
Bash Introduction
62gerente
608
210k
Fireside Chat
paigeccino
34
3k
Done Done
chrislema
181
16k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Transcript
1)1ͷNJEEMFXBSFΛ ͍͜ͳͨ͢Ίʹ 1)1ΧϯϑΝϨϯεઋ ߹ಉձࣾςϯϚυɹࢁԬ
ࣗݾհ ࢁԬ!IJSP@Z 1)1ͱ͔/PEFKTͷΤϯδχΞ 1)1ͷ͜Ζ͔Β ߹ಉձࣾςϯϚυදࣾһ
ɹɹ߹ಉձࣾςϯϚυ!! Ϗδωεࢧԉࣄۀ ࣾ֎$50ͱ͔ΞυόΠβʔ *OOPWBUPS+BQBO64&/.FEJBͳͲ αʔϏε։ൃࣄۀ
JSVDBNJNFNPDPOBTV
ࠓճͷ͓ͷΰʔϧ NJEEMFXBSFͱ͍͏ߟ͑ํ͕Θ͔Δ ฉ͍ͨͱ͖ʹΠϝʔδ͕ු͔Ϳ ར༻γʔϯ͕૾Ͱ͖Δ ϑϨʔϜϫʔΫͰ͑Δ͔Θ͔Δ
͓Λ࢝ΊΔલʹ
લճ·Ͱͷ͋Β͢͡ 1)1ΧϯϑΝϨϯεؔ 4MJN'SBNFXPSLͰ࢝ΊΔ1)1ͷ NJEEMFXBSF 1)1ΧϯϑΝϨϯε 1)1'*(ͷ)551ॲཧඪ४ͷઃܭ
ͳͥ143ʹͳͬͨͷ͔
Ͱɺ͋ΒͨΊͯ
XFCΞϓϦͱ ϦΫΤετΛड͚औΓʢೖྗʣ ͍Ζ͍ΖॲཧΛͯ͠ ೝূͱ͔%#ͷॲཧͱ͔ ϨεϙϯεΛฦ͢ʢग़ྗʣ
؆୯ʹඳ͘ͱ͜͏
XFCΞϓϦͷલॲཧ શϦΫΤετڞ௨Ͱ͍ͨ͠ॲཧ ϩάΠϯೝূ %#͔ΒͷσʔλऔಘɹͳͲ ΞϓϦέʔγϣϯຊମͷલʹ ॲཧΛڬΊΔΑ͏ʹ͢ΕΑ͍ͷͰ
ϑΟϧλʔʢલॲཧʣ
XFCΞϓϦͷޙॲཧ શϦΫΤετڞ௨ͷॲཧɺ·ͩ͋Δ ϩάग़ྗ ॲཧޙʹ·ͱΊͯϝʔϧૹ৴ ΞϓϦέʔγϣϯຊମͷޙʹ ॲཧΛڬΊΔΑ͏ʹͰ͖ΔͱΑͦ͞͏
ϑΟϧλʔʢޙॲཧʣ
ͯ͞ɺͪΐͬͱ ൃΛస͢Δ
ೖΕࢠߏ ೖΕࢠࣜʹॲཧΛ ͭͳ͍Ͱ͍͘ΈΛߟ͑Δ ྫؔ"ͱؔ#Λ࣮͢Δ ؔ"ͦͷॲཧͷதͰؔ#Λ ࣮ߦɺͦͷ݁ՌΛฦ͢Α͏ʹ͢Δ
1)1Ͱॻ͍ͯΈΔͱ $a = function (string $str, \Closure $next) : string
{ echo 'A'; // લॲཧΆ͍ $result = $next($str); // ࣍ΛݺͿ echo 'C'; // ޙॲཧΆ͍ return $result; }; $b = function (string $str) : string { echo 'B'; return strtoupper($str); }; $a('hoge', $b); // ABC
ೖΕࢠߏ
͞ΒʹೖΕࢠߏ
λϚωΪΈ͍ͨʁ QIPUPCZEBSXJO#FMMMJDFOTFEVOEFS$$#: IUUQTXXXqJDLSDPNQIPUPTEBSXJOCFMM
ೖΕࢠߏͷಛ ΞϓϦຊମΛแΉΑ͏ʹ࣮ ֎ଆ͔Β৽͍͠;Δ·͍ΛՃͰ͖Δ ࢀߟ"01ʢΞεϖΫτࢦϓϩάϥϛϯάʣ ڞ௨ͷॲཧΛԣஅతʹݺͼग़͠
લॲཧɾޙॲཧΛࢦఆͰ͖Δ
XFCΞϓϦʹద༻
1)1ʹ͓͚Δྺ࢙
4UBDL1)1 IUUQTTUBDLQIQDPN l$PNQPTJOH)UUQ,FSOFM*OUFSGBDF NJEEMFXBSFTTJODFz l8IBUEPXFXBOU 3FVTFBUUIF XFCMBZFSz
4ZNGPOZͷ)UUQ,FSOFM*OUFSGBDF
4UBDL1)1
143ͱʁ IUUQTXXXQIQpHPSHQTS l1)14UBOEBSET3FDPNNFOEBUJPOTz ܾఆతͳʮඪ४ʯͰͳ͍ ͋͘·ͰΦεεϝɺקࠂ
ίϛϡχςΟʔͰӨڹྗେ
Α͘ฉ͘143 143#BTJD$PEJOH4UBOEBSE 143$PEJOH4UZMF(VJEF 143-PHHFS*OUFSGBDF 143"VUPMPBEJOH4UBOEBSE
143 IUUQTXXXQIQpHPSHQTSQTS )551NFTTBHFJOUFSGBDFT 1TSa)UUQa.FTTBHFa3FRVFTU*OUFSGBDF 1TSa)UUQa.FTTBHFa3FTQPOTF*OUFSGBDF
XFCΞϓϦͷೖग़ྗͷඪ४Խ
143 IUUQTXXXQIQpHPSHQTSQTS )5514FSWFS3FRVFTU)BOEMFST 1TSa)UUQa4FSWFSa3FRVFTU)BOEMFS*OUFSGBDF 1TSa)UUQa4FSWFSa.JEEMFXBSF*OUFSGBDF
XFCΞϓϦͷඪ४Խ
ઌ΄Ͳͷਤ
143143
.JEEMFXBSF*OUFSGBDF interface MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface
$handler ): ResponseInterface; }
3FRVFTU)BOEMFS interface RequestHandlerInterface { public function handle( ServerRequestInterface $request ):
ResponseInterface; }
࠷ۙͷ143ͷ IUUQTUXJUUFSDPNGBCQPUTUBUVT 3FNPWF4ZNGPOZCZGBCQPUu1VMM 3FRVFTUuQIQpHpHTUBOEBSET
ϑϨʔϜϫʔΫͱ NJEEMXBSFͷؔ
4MJN'SBNFXPSLW IUUQTXXXTMJNGSBNFXPSLDPN )5513PVUFS .JEEMFXBSF 1434VQQPSU
%FQFOEFODZ*OKFDUJPO 143
4MJN class ExampleMiddleware { public function __invoke( ServerRequestInterface $request,
ResponseInterface $response, callable $next ): ResponseInterface { return $next($request, $response); } }
4MJN'SBNFXPSLW IUUQTHJUIVCDPNTMJNQIQ4MJN CMPCY$)"/(&-0(NE 4MJNOPMPOHFSTIJQTXJUIB143 JNQMFNFOUBUJPO 1433FRVFTU)BOEMFSTDBOOPX CFVTFEBTSPVUFDBMMBCMFT
;FOE&YQSFTTJWF IUUQTEPDT[FOEGSBNFXPSLDPN [FOEFYQSFTTJWF 1431433PVUJOH143 ඪ४Λҙࣝ
-BSBWFM IUUQTMBSBWFMDPNEPDT NJEEMFXBSF 143ͷ࣮Ͱͳ͍ ैདྷͷDPOUSPMMFSͷิॿతͳׂ ڞ௨ॲཧΛ࣮͢ΔͨΊͷΈ
-BSBWFM class ExampleMiddleware { public function handle( \Illuminate\Http\Request $request,
\Closure $next ) { return $next($request); } }
4ZNGPOZ NJEEMFXBSFʹ૬͢Δػೳͳ͍ ػೳͱͯ͠ϑΟϧλʔ͕͋Δ IUUQTTZNGPOZDPNEPDDVSSFOU FWFOU@EJTQBUDIFS CFGPSF@BGUFS@pMUFSTIUNM
$BLF1)1 IUUQTCPPLDBLFQIQPSHFO DPOUSPMMFSTNJEEMFXBSFIUNM ͔Β143ʹରԠ $43'τʔΫϯνΣοΫͷ࣮ͳͲ͕ NJEEMFXBSFͰͳ͞Ε͍ͯΔ
$BLF1)1 class ExampleMiddleware { public function handle( ServerRequestInterface $request,
ResponseInterface $response, callable $next ): \Cake\Http\Response { return $next($request, $response); } }
ͯ͞ɺ·ͱΊ
ͪΐͬͱେ͛͞ͳ
ͦͦϑϨʔϜϫʔΫͱ ϦΫΤετΛड͚औΔ SPVUJOHΛݩʹߦ͏ॲཧΛબ͢Δ ॲཧΛݺͼग़͠ɺ࣮ߦ ݁ՌΛϨεϙϯεͱͯ͠ग़ྗ͢Δ
ϑϨʔϜϫʔΫ ࡞Εͦ͏͡Όͳ͍Ͱ͔͢ʁ
ϑϨʔϜϫʔΫϨγϐ 143ͷ࣮ʢ[FOEEJBDUPSPTͳͲʣ SPVUJOH࣮ʢ'BTU3PVUFͳͲʣ NJEEMFXBSFͷ࣮ߦʢ.JEEMFMBOEͳͲʣ ग़ྗʢ[FOEIUUQIBOEMFSSVOOFSͳͲʣ
࣮ྫ IUUQTMPHNJKQUFDIBSUJDMFT ϩάϛʔͷϦχϡʔΞϧ lࠓճͷϦχϡʔΞϧͰ͜ͷ143 Λར༻͢Δ͜ͱͰɺಛఆͷ8FCϑϨʔ ϜϫʔΫΛར༻ͤͣʹΞϓϦΛ࣮͢ Δ͜ͱʹ͠·ͨ͠z
ΦϨΦϨϑϨʔϜϫʔΫ ϑϨʔϜϫʔΫ؆୯ʹ࡞ΕΔ 143ʹ४ڌ͓͚ͯ͠ɺޙ͔Β;FOE &YQSFTTJWFͳͲʹΓ͑Δ͜ͱՄೳ ͪΖΜɺٯ બࢶͷҰͭͱͯ͠ɺ͋Γ͔
NJEEMFXBSF ͍͔͕Ͱ͔ͨ͠ʁ
·ͱΊ ॲཧΛNJEEMFXBSFͰׂ هड़͕؆ܿʹɺςετ༰қʹ 143Ͱඪ४Խ͞ΕΔ͜ͱͰࠩ͠ସ͑Մೳʹ %*ίϯςφͱͷΈ߹Θͤศར
ίϯετϥΫλΠϯδΣΫγϣϯ
͋Γ͕ͱ͏͍͟͝·ͨ͠