diff --git a/README.md b/README.md index bcf07f4..5db452b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,26 @@ Further details can be found here: ## Slim 4 integration +```php +add(new SameSiteCookieMiddleware()); + +// ... + +$app->run(); +``` + +**Example with configuration and the session starter middleware.** + Slim 4 uses a LIFO (last in, first out) middleware stack, so we have to add the middleware in reverse order: @@ -57,6 +77,7 @@ $app = AppFactory::create(); // ... +// Optional: Add custom configuration $configuration = new SameSiteCookieConfiguration(); // Register the samesite cookie middleware diff --git a/src/SameSiteCookieMiddleware.php b/src/SameSiteCookieMiddleware.php index 806598b..703dcaa 100644 --- a/src/SameSiteCookieMiddleware.php +++ b/src/SameSiteCookieMiddleware.php @@ -26,14 +26,14 @@ final class SameSiteCookieMiddleware implements MiddlewareInterface /** * The constructor. * - * @param SameSiteCookieConfiguration $configuration The configuration + * @param SameSiteCookieConfiguration|null $configuration The configuration * @param SessionHandlerInterface|null $sessionHandler The session handler */ public function __construct( - SameSiteCookieConfiguration $configuration, + SameSiteCookieConfiguration $configuration = null, SessionHandlerInterface $sessionHandler = null ) { - $this->configuration = $configuration; + $this->configuration = $configuration ?: new SameSiteCookieConfiguration(); $this->sessionHandler = $sessionHandler ?: new PhpSessionHandler(); }