Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use PHP 8.1 syntax #75

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/LazySession.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ final class LazySession implements
SessionInterface,
InitializeSessionIdInterface
{
private SessionPersistenceInterface $persistence;

private ?SessionInterface $proxiedSession = null;

/**
* Request instance to use when calling $persistence->initializeSessionFromRequest()
*/
private ServerRequestInterface $request;

public function __construct(SessionPersistenceInterface $persistence, ServerRequestInterface $request)
{
$this->persistence = $persistence;
$this->request = $request;
public function __construct(
private readonly SessionPersistenceInterface $persistence,
/**
* Request instance to use when calling $persistence->initializeSessionFromRequest()
*/
private readonly ServerRequestInterface $request
) {
}

public function regenerate(): SessionInterface
Expand Down
27 changes: 13 additions & 14 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ class Session implements
*/
private array $data;

/**
* The session identifier, if any.
*
* This is present in the session to allow the session persistence
* implementation to be stateless. When present here, we can query for it
* when it is time to persist the session, instead of relying on state in
* the persistence instance (which may be shared between multiple
* requests).
*/
private string $id;

private bool $isRegenerated = false;

/**
Expand All @@ -49,10 +38,20 @@ class Session implements
private int $sessionLifetime = 0;

/** @param array<string, mixed> $data */
public function __construct(array $data, string $id = '')
{
public function __construct(
array $data,
/**
* The session identifier, if any.
*
* This is present in the session to allow the session persistence
* implementation to be stateless. When present here, we can query for it
* when it is time to persist the session, instead of relying on state in
* the persistence instance (which may be shared between multiple
* requests).
*/
private string $id = ''
) {
$this->data = $this->originalData = $data;
$this->id = $id;

/** @psalm-suppress MixedAssignment */
$lifetime = $data[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] ?? null;
Expand Down
5 changes: 1 addition & 4 deletions src/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ class SessionMiddleware implements MiddlewareInterface
{
public const SESSION_ATTRIBUTE = 'session';

private SessionPersistenceInterface $persistence;

public function __construct(SessionPersistenceInterface $persistence)
public function __construct(private readonly SessionPersistenceInterface $persistence)
{
$this->persistence = $persistence;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Expand Down
2 changes: 1 addition & 1 deletion test/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class RequestHandler implements RequestHandlerInterface
{
private ?ServerRequestInterface $received = null;
private ResponseInterface $defaultResponse;
private readonly ResponseInterface $defaultResponse;

public function __construct(
ResponseInterface|null $defaultResponse = null,
Expand Down