aboutsummaryrefslogtreecommitdiff
path: root/tests/Fixtures/CsrfLoggingMiddleware.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Fixtures/CsrfLoggingMiddleware.php')
-rw-r--r--tests/Fixtures/CsrfLoggingMiddleware.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/Fixtures/CsrfLoggingMiddleware.php b/tests/Fixtures/CsrfLoggingMiddleware.php
new file mode 100644
index 0000000..4fa25d5
--- /dev/null
+++ b/tests/Fixtures/CsrfLoggingMiddleware.php
@@ -0,0 +1,30 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Tests\Fixtures;
+
+use ArrayObject;
+use BrettParson\MiniRoute\Http\RequestInterface;
+use BrettParson\MiniRoute\Http\ResponseInterface;
+use BrettParson\MiniRoute\Middleware\MiddlewareInterface;
+
+/**
+ * Logs before/after into a shared log. Stands in for the real app's CSRF
+ * guard, applied to the /admin prefix for POST only.
+ */
+final class CsrfLoggingMiddleware implements MiddlewareInterface
+{
+ public function __construct(private readonly ArrayObject $log)
+ {
+ }
+
+ public function handle(RequestInterface $request, callable $next): ResponseInterface
+ {
+ $this->log->append('csrf:before');
+ $response = $next($request);
+ $this->log->append('csrf:after');
+
+ return $response;
+ }
+}