Skip to content

Commit

Permalink
make cookie expire configurable (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat authored Oct 6, 2023
1 parent 2771bba commit e0566fc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ jobs:
continue-on-error: true
run: |
bin/console cache:warmup --env=test
vendor/bin/ecs check ${{ github.workspace }}/lib/test-bundle/src/I18nBundle --config ${{ github.workspace }}/lib/test-bundle/ecs.php
vendor/bin/ecs check ${{ github.workspace }}/lib/test-bundle/src/ --config ${{ github.workspace }}/lib/test-bundle/ecs.php
5 changes: 4 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->booleanNode('httpOnly')
->defaultTrue()
->end()
->scalarnode('sameSite')
->scalarNode('expire')
->defaultValue('+1 year')
->end()
->scalarNode('sameSite')
->defaultValue(Cookie::SAMESITE_LAX)
->validate()
->ifNotInArray([Cookie::SAMESITE_NONE, Cookie::SAMESITE_LAX, Cookie::SAMESITE_STRICT])
Expand Down
3 changes: 2 additions & 1 deletion src/Helper/CookieHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public function set(Response $response, array $params): Cookie
$secure = $cookieConfig['secure'];
$httpOnly = $cookieConfig['httpOnly'];
$sameSite = $cookieConfig['sameSite'];
$expire = is_string($cookieConfig['expire']) ? strtotime($cookieConfig['expire']) : $cookieConfig['expire'];

$cookieData = base64_encode(json_encode($params));
$cookie = new Cookie(Definitions::REDIRECT_COOKIE_NAME, $cookieData, strtotime('+1 year'), $path, $domain, $secure, $httpOnly, false, $sameSite);
$cookie = new Cookie(Definitions::REDIRECT_COOKIE_NAME, $cookieData, $expire, $path, $domain, $secure, $httpOnly, false, $sameSite);
$response->headers->setCookie($cookie);

return $cookie;
Expand Down

0 comments on commit e0566fc

Please sign in to comment.