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
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
570
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
670
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
350
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.8k
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Designing for Performance
lara
604
68k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Teambox: Starting and Learning
jrom
133
8.8k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Designing for humans not robots
tammielis
250
25k
The Invisible Side of Design
smashingmag
298
50k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
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Ͱඪ४Խ͞ΕΔ͜ͱͰࠩ͠ସ͑Մೳʹ %*ίϯςφͱͷΈ߹Θͤศར
ίϯετϥΫλΠϯδΣΫγϣϯ
͋Γ͕ͱ͏͍͟͝·ͨ͠