diff --git a/src/LazySession.php b/src/LazySession.php index da327ba..2068dcf 100644 --- a/src/LazySession.php +++ b/src/LazySession.php @@ -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 diff --git a/src/Session.php b/src/Session.php index 2244784..bfadb01 100644 --- a/src/Session.php +++ b/src/Session.php @@ -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; /** @@ -49,10 +38,20 @@ class Session implements private int $sessionLifetime = 0; /** @param array $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; diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 611d035..927cfed 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -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 diff --git a/test/RequestHandler.php b/test/RequestHandler.php index 4cb477f..6941717 100644 --- a/test/RequestHandler.php +++ b/test/RequestHandler.php @@ -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,