I have a middleware I’ve designed that is deleting a session value when the request is to a controller/action that is not in a defined list.
Problem is, DebugKit is also going through my middleware and it killing my session value even when MY request is in the defined list.
I’d rather not add all the paths DebugKit follows. It would be better to prevent DebugKit from interacting with this particular middleware.
Is there any way to do that?
Found my answer. I’ve got the request in the middleware so
!$request->getParam('plugin') === 'DebugKit'
in a conditional did the job.
Here is the code for completeness.
Some query filtering arguments are retained in the session and will persist as long as the user remains within the developer defined scope of pages.
So, you could filter an index page and have that persist even after visiting the view page for a record.
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
/* @var ServerRequest $request */
/* @var Session $session */
$session = $request->getSession();
$sessionData = $session->read();
$requestPath = $request->getParam('controller') . '_' . $request->getParam('action');
$filterPath = Hash::get($sessionData, 'filter.path' ) ?? 'empty';
$allowedPaths = Configure::read('filter_scopes.' . $filterPath);
$request->getParam('plugin') !== 'DebugKit' //ignore all DebugKit requests
&& isset($sessionData['filter']['path']) //ignore if there is no filter stored
&& $filterPath !== $requestPath //ignore if we're actually on the original page
&& !in_array($requestPath, $allowedPaths) //ignore if this path is an approved path
$session->delete('filter'); //well then, delete the filter
unset($session, $sessionData, $requestPath, $allowedPaths); //be a good middleware citizen
return $next($request, $response);