-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from Slamdunk/config
Add Config object, drop factory methods
- Loading branch information
Showing
6 changed files
with
407 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/Storageless/Http/SessionMiddlewareConfiguration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PSR7Sessions\Storageless\Http; | ||
|
||
use Dflydev\FigCookies\Modifier\SameSite; | ||
use Dflydev\FigCookies\SetCookie; | ||
use Lcobucci\Clock\Clock; | ||
use Lcobucci\Clock\SystemClock; | ||
use Lcobucci\JWT\Configuration; | ||
|
||
/** @immutable */ | ||
final class SessionMiddlewareConfiguration | ||
{ | ||
private Configuration $jwtConfiguration; | ||
private Clock $clock; | ||
private SetCookie $cookie; | ||
/** @var positive-int */ | ||
private int $idleTimeout = 43200; | ||
/** @var positive-int */ | ||
private int $refreshTime = 60; | ||
/** @var literal-string */ | ||
private string $sessionAttribute = SessionMiddleware::SESSION_ATTRIBUTE; | ||
|
||
public function __construct( | ||
Configuration $jwtConfiguration, | ||
) { | ||
$this->jwtConfiguration = clone $jwtConfiguration; | ||
|
||
$this->clock = SystemClock::fromSystemTimezone(); | ||
$this->cookie = SetCookie::create('__Secure-slsession') | ||
->withSecure(true) | ||
->withHttpOnly(true) | ||
->withSameSite(SameSite::lax()) | ||
->withPath('/'); | ||
} | ||
|
||
public function getJwtConfiguration(): Configuration | ||
{ | ||
return $this->jwtConfiguration; | ||
} | ||
|
||
public function getClock(): Clock | ||
{ | ||
return $this->clock; | ||
} | ||
|
||
public function getCookie(): SetCookie | ||
{ | ||
return $this->cookie; | ||
} | ||
|
||
/** @return positive-int */ | ||
public function getIdleTimeout(): int | ||
{ | ||
return $this->idleTimeout; | ||
} | ||
|
||
/** @return positive-int */ | ||
public function getRefreshTime(): int | ||
{ | ||
return $this->refreshTime; | ||
} | ||
|
||
/** @return literal-string */ | ||
public function getSessionAttribute(): string | ||
{ | ||
return $this->sessionAttribute; | ||
} | ||
|
||
public function withJwtConfiguration(Configuration $jwtConfiguration): self | ||
{ | ||
$new = clone $this; | ||
$new->jwtConfiguration = clone $jwtConfiguration; | ||
|
||
return $new; | ||
} | ||
|
||
public function withClock(Clock $clock): self | ||
{ | ||
$new = clone $this; | ||
$new->clock = clone $clock; | ||
|
||
return $new; | ||
} | ||
|
||
public function withCookie(SetCookie $cookie): self | ||
{ | ||
$new = clone $this; | ||
$new->cookie = clone $cookie; | ||
|
||
return $new; | ||
} | ||
|
||
/** @param positive-int $idleTimeout */ | ||
public function withIdleTimeout(int $idleTimeout): self | ||
{ | ||
$new = clone $this; | ||
$new->idleTimeout = $idleTimeout; | ||
|
||
return $new; | ||
} | ||
|
||
/** @param positive-int $refreshTime */ | ||
public function withRefreshTime(int $refreshTime): self | ||
{ | ||
$new = clone $this; | ||
$new->refreshTime = $refreshTime; | ||
|
||
return $new; | ||
} | ||
|
||
/** @param literal-string $sessionAttribute */ | ||
public function withSessionAttribute(string $sessionAttribute): self | ||
{ | ||
$new = clone $this; | ||
$new->sessionAttribute = $sessionAttribute; | ||
|
||
return $new; | ||
} | ||
} |
Oops, something went wrong.