Используя промежуточное ПО для торта PHP, я заметил, что функция process () может выполняться несколько раз. Это видно из лог-файлов. Я не уверен, что это может иметь побочные эффекты. Пример ниже:
class FooMiddleware implements MiddlewareInterface
{
use LogTrait;
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface
{
$this->log('Repeat?');
return $handler->handle($request);
}
}
В моих журналах я получаю идентичные метки времени.
2020-04-13 23:15:21 Error: Repeat?
2020-04-13 23:15:21 Error: Repeat?
Ожидается ли это?
РЕДАКТИРОВАТЬ
$middlewareQueue
// Catch any exceptions in the lower layers,
// and make an error page/response
->add(new ErrorHandlerMiddleware(Configure::read('Error')))
// Handle plugin/theme assets like CakePHP normally does.
->add(new AssetMiddleware([
'cacheTime' => Configure::read('Asset.cacheTime'),
]))
// Add routing middleware.
// If you have a large number of routes connected, turning on routes
// caching in production could improve performance. For that when
// creating the middleware instance specify the cache config name by
// using it's second constructor argument:
// `new RoutingMiddleware($this, '_cake_routes_')`
->add(new RoutingMiddleware($this))
->add($csrf)
->add(new AuthenticationMiddleware($this))
->add(new FooMiddleware())
->add(new AuthorizationMiddleware($this));
if (Configure::read('debug')) {
// Disable authz for debugkit
$middlewareQueue->add(function ($req, $res, $next) {
if ($req->getParam('plugin') === 'DebugKit') {
$req->getAttribute('authorization')->skipAuthorization();
}
return $next($req, $res);
});
}
return $middlewareQueue;