Skip to content

Commit

Permalink
Make SameSiteCookieConfiguration optional
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Jan 11, 2021
1 parent 75977d8 commit 805d82d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ Further details can be found here:

## Slim 4 integration

```php
<?php

use Selective\SameSiteCookie\SameSiteCookieMiddleware;
use Slim\Factory\AppFactory;

$app = AppFactory::create();

// ...

// Register the samesite cookie middleware
$app->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:

Expand All @@ -57,6 +77,7 @@ $app = AppFactory::create();

// ...

// Optional: Add custom configuration
$configuration = new SameSiteCookieConfiguration();

// Register the samesite cookie middleware
Expand Down
6 changes: 3 additions & 3 deletions src/SameSiteCookieMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 805d82d

Please sign in to comment.