예. 그렇습니다. 미들웨어는 호출 가능한 스택의 또 다른 계층입니다.
은 전이나 코드에 정의 된 후 적용 여부 :
<?php
// Add middleware to your app
$app->add(function ($request, $response, $next) {
$response->getBody()->write('BEFORE');
$response = $next($request, $response);
$response->getBody()->write('AFTER');
return $response;
});
$app->get('/', function ($request, $response, $args) {
$response->getBody()->write(' Hello ');
return $response;
});
$app->run();
이 것 출력이 HTTP 응답 본문 :
BEFORE Hello AFTER
따라서, 귀하의 경우에는 내가 뭔가를 갈 것을 이렇게 :
<?php
class AfterMiddleware
{
public function __invoke($request, $response, $next)
{
// FIRST process by controller
$response = $next($request, $response);
// You can still access request attributes
$attrVal = $request->getAttribute('foo');
// THEN check validation status and act accordingly
$isValid = true;
if ($isValid) {
// Send to the bucket
}
}
}