diff --git a/Neos.Flow/Classes/Session/Session.php b/Neos.Flow/Classes/Session/Session.php index 4268fcb078..f5148b1d0f 100644 --- a/Neos.Flow/Classes/Session/Session.php +++ b/Neos.Flow/Classes/Session/Session.php @@ -198,7 +198,7 @@ public static function createRemoteFromSessionMetaData(SessionMetaData $sessionM * @param array $tags * @return Session */ - public static function createFromCookieAndSessionInformation(Cookie $sessionCookie, string $storageIdentifier, int $lastActivityTimestamp, array $tags = []) + public static function createFromCookieAndSessionInformation(Cookie $sessionCookie, string $storageIdentifier, int $lastActivityTimestamp, array $tags = []): self { $session = new static(); $session->sessionMetaData = new SessionMetaData( @@ -215,9 +215,8 @@ public static function createFromCookieAndSessionInformation(Cookie $sessionCook * Injects the Flow settings * * @param array $settings Settings of the Flow package - * @return void */ - public function injectSettings(array $settings) + public function injectSettings(array $settings): void { $this->sessionCookieName = $settings['session']['name']; $this->sessionCookieLifetime = (integer)$settings['session']['cookie']['lifetime']; @@ -233,9 +232,8 @@ public function injectSettings(array $settings) * Injects the (system) logger based on PSR-3. * * @param LoggerInterface $logger - * @return void */ - public function injectLogger(LoggerInterface $logger) + public function injectLogger(LoggerInterface $logger): void { $this->logger = $logger; } @@ -251,10 +249,9 @@ public function getSessionCookie(): Cookie /** * Tells if the session has been started already. * - * @return boolean * @api */ - public function isStarted() + public function isStarted(): bool { return $this->started; } @@ -266,7 +263,7 @@ public function isStarted() * @return boolean true if the session is remote, false if this is the current session * @api */ - public function isRemote() + public function isRemote(): bool { return $this->remote; } @@ -274,12 +271,11 @@ public function isRemote() /** * Starts the session, if it has not been already started * - * @return void * @throws \Exception * @see CookieEnabledInterface * @api */ - public function start() + public function start(): void { if ($this->started === false) { $this->sessionMetaData = SessionMetaData::createWithTimestamp($this->now); @@ -303,7 +299,7 @@ public function start() * @return boolean * @api */ - public function canBeResumed() + public function canBeResumed(): bool { if ($this->sessionCookie === null || $this->started === true) { return false; @@ -327,7 +323,7 @@ public function canBeResumed() * @return null|integer If a session was resumed, the inactivity of this session since the last request is returned * @api */ - public function resume() + public function resume(): null|int { if ($this->started === false && $this->canBeResumed()) { $this->started = true; @@ -363,7 +359,7 @@ public function resume() * @throws Exception\SessionNotStartedException * @api */ - public function getId() + public function getId(): string { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to retrieve the session identifier, but the session has not been started yet.)', 1351171517); @@ -380,7 +376,7 @@ public function getId() * @throws Exception\OperationNotSupportedException * @api */ - public function renewId() + public function renewId(): string { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to renew the session identifier, but the session has not been started yet.', 1351182429); @@ -404,7 +400,7 @@ public function renewId() * @return mixed The contents associated with the given key * @throws Exception\SessionNotStartedException */ - public function getData($key) + public function getData(string $key): mixed { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to get session data, but the session has not been started yet.', 1351162255); @@ -419,7 +415,7 @@ public function getData($key) * @return boolean * @throws Exception\SessionNotStartedException */ - public function hasKey($key) + public function hasKey(string $key): bool { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to check a session data entry, but the session has not been started yet.', 1352488661); @@ -432,12 +428,11 @@ public function hasKey($key) * * @param string $key The key under which the data should be stored * @param mixed $data The data to be stored - * @return void * @throws Exception\DataNotSerializableException * @throws Exception\SessionNotStartedException * @api */ - public function putData($key, $data) + public function putData(string $key, mixed $data): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to create a session data entry, but the session has not been started yet.', 1351162259); @@ -459,7 +454,7 @@ public function putData($key, $data) * @throws Exception\SessionNotStartedException * @api */ - public function getLastActivityTimestamp() + public function getLastActivityTimestamp(): int { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to retrieve the last activity timestamp of a session which has not been started yet.', 1354290378); @@ -474,12 +469,11 @@ public function getLastActivityTimestamp() * recommended to use namespaced tags such as "Acme-Demo-MySpecialTag". * * @param string $tag The tag – must match be a valid cache frontend tag - * @return void * @throws Exception\SessionNotStartedException * @throws \InvalidArgumentException * @api */ - public function addTag($tag) + public function addTag(string $tag): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to tag a session which has not been started yet.', 1355143533); @@ -494,11 +488,10 @@ public function addTag($tag) * Removes the specified tag from this session. * * @param string $tag The tag – must match be a valid cache frontend tag - * @return void * @throws Exception\SessionNotStartedException * @api */ - public function removeTag($tag) + public function removeTag(string $tag): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to tag a session which has not been started yet.', 1355150140); @@ -510,11 +503,11 @@ public function removeTag($tag) /** * Returns the tags this session has been tagged with. * - * @return array The tags or an empty array if there aren't any + * @return string[] The tags or an empty array if there aren't any * @throws Exception\SessionNotStartedException * @api */ - public function getTags() + public function getTags(): array { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to retrieve tags from a session which has not been started yet.', 1355141501); @@ -525,10 +518,9 @@ public function getTags() /** * Updates the last activity time to "now". * - * @return void * @throws Exception\SessionNotStartedException */ - public function touch() + public function touch(): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to touch a session, but the session has not been started yet.', 1354284318); @@ -545,10 +537,9 @@ public function touch() /** * Explicitly writes and closes the session * - * @return void * @api */ - public function close() + public function close(): void { $this->shutdownObject(); } @@ -557,11 +548,10 @@ public function close() * Explicitly destroys all session data * * @param string $reason A reason for destroying the session – used by the LoggingAspect - * @return void * @throws Exception\SessionNotStartedException * @api */ - public function destroy($reason = null) + public function destroy(string $reason = null): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to destroy a session which has not been started yet.', 1351162668); @@ -583,13 +573,12 @@ public function destroy($reason = null) * This method must not be called manually – it is invoked by Flow's object * management. * - * @return void * @throws Exception\DataNotSerializableException * @throws Exception\SessionNotStartedException * @throws NotSupportedByBackendException * @throws \Neos\Cache\Exception */ - public function shutdownObject() + public function shutdownObject(): void { if ($this->started === true && $this->remote === false) { if ($this->sessionMetaDataStore->has($this->sessionMetaData->sessionIdentifier)) { @@ -605,7 +594,7 @@ public function shutdownObject() * * @return boolean true if the session expired, false if not */ - protected function autoExpire() + protected function autoExpire(): bool { $lastActivitySecondsAgo = $this->now - $this->sessionMetaData->lastActivityTimestamp; $expired = false; @@ -627,9 +616,8 @@ protected function autoExpire() * The session cache entry is also tagged with "session", the session identifier * and any custom tags of this session, prefixed with TAG_PREFIX. * - * @return void */ - protected function writeSessionMetaDataCacheEntry() + protected function writeSessionMetaDataCacheEntry(): void { $this->sessionMetaDataStore->store($this->sessionMetaData); } diff --git a/Neos.Flow/Classes/Session/SessionInterface.php b/Neos.Flow/Classes/Session/SessionInterface.php index e1cfafd104..1025599869 100644 --- a/Neos.Flow/Classes/Session/SessionInterface.php +++ b/Neos.Flow/Classes/Session/SessionInterface.php @@ -21,28 +21,28 @@ interface SessionInterface * * @return boolean */ - public function isStarted(); + public function isStarted(): bool; /** * Starts the session, if is has not been already started * * @return void */ - public function start(); + public function start(): void; /** * Returns true if there is a session that can be resumed. false otherwise * * @return boolean */ - public function canBeResumed(); + public function canBeResumed(): bool; /** * Resumes an existing session, if any. * - * @return void + * @return null|int */ - public function resume(); + public function resume(): null|int; /** * Returns the current session ID. @@ -50,7 +50,7 @@ public function resume(); * @return string The current session ID * @throws Exception\SessionNotStartedException */ - public function getId(); + public function getId(): string; /** * Generates and propagates a new session ID and transfers all existing data @@ -60,7 +60,7 @@ public function getId(); * * @return string The new session ID */ - public function renewId(); + public function renewId(): string; /** * Returns the content (mixed) associated with the given key. @@ -69,7 +69,7 @@ public function renewId(); * @return mixed The contents associated with the given key * @throws Exception\SessionNotStartedException */ - public function getData($key); + public function getData(string $key): mixed; /** * Returns true if $key is available. @@ -77,7 +77,7 @@ public function getData($key); * @param string $key * @return boolean */ - public function hasKey($key); + public function hasKey(string $key): bool; /** * Stores the given data under the given key in the session @@ -87,7 +87,7 @@ public function hasKey($key); * @return void * @throws Exception\SessionNotStartedException */ - public function putData($key, $data); + public function putData(string $key, mixed $data): void; /** * Tags this session with the given tag. @@ -101,7 +101,7 @@ public function putData($key, $data); * @throws \InvalidArgumentException * @api */ - public function addTag($tag); + public function addTag(string $tag): void; /** * Removes the specified tag from this session. @@ -111,16 +111,16 @@ public function addTag($tag); * @throws Exception\SessionNotStartedException * @api */ - public function removeTag($tag); + public function removeTag(string $tag): void; /** * Returns the tags this session has been tagged with. * - * @return array The tags or an empty array if there aren't any + * @return string[] The tags or an empty array if there aren't any * @throws Exception\SessionNotStartedException * @api */ - public function getTags(); + public function getTags(): array; /** * Updates the last activity time to "now". @@ -128,7 +128,7 @@ public function getTags(); * @return void * @api */ - public function touch(); + public function touch(): void; /** * Returns the unix time stamp marking the last point in time this session has @@ -140,7 +140,7 @@ public function touch(); * @return integer unix timestamp * @api */ - public function getLastActivityTimestamp(); + public function getLastActivityTimestamp(): int; /** * Explicitly writes (persists) and closes the session @@ -148,7 +148,7 @@ public function getLastActivityTimestamp(); * @return void * @throws Exception\SessionNotStartedException */ - public function close(); + public function close(): void; /** * Explicitly destroys all session data @@ -157,5 +157,5 @@ public function close(); * @return void * @throws Exception\SessionNotStartedException */ - public function destroy($reason = null); + public function destroy(string $reason = null): void; } diff --git a/Neos.Flow/Classes/Session/TransientSession.php b/Neos.Flow/Classes/Session/TransientSession.php index 3e7b81f2a7..2aa51ea8da 100644 --- a/Neos.Flow/Classes/Session/TransientSession.php +++ b/Neos.Flow/Classes/Session/TransientSession.php @@ -61,17 +61,15 @@ class TransientSession implements SessionInterface * * @return boolean */ - public function isStarted() + public function isStarted(): bool { return $this->started; } /** * Starts the session, if it has not been already started - * - * @return void */ - public function start() + public function start(): void { $this->sessionId = Algorithms::generateRandomString(13); $this->started = true; @@ -79,24 +77,21 @@ public function start() /** * Returns true if there is a session that can be resumed. false otherwise - * - * @return boolean */ - public function canBeResumed() + public function canBeResumed(): bool { return true; } /** * Resumes an existing session, if any. - * - * @return void */ - public function resume() + public function resume(): null|int { if ($this->started === false) { $this->start(); } + return null; } /** @@ -105,7 +100,7 @@ public function resume() * * @return string The new session ID */ - public function renewId() + public function renewId(): string { $this->sessionId = Algorithms::generateRandomString(13); return $this->sessionId; @@ -117,7 +112,7 @@ public function renewId() * @return string The current session ID * @throws Exception\SessionNotStartedException */ - public function getId() + public function getId(): string { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1218034659); @@ -132,7 +127,7 @@ public function getId() * @return mixed The data associated with the given key or NULL * @throws Exception\SessionNotStartedException */ - public function getData($key) + public function getData(string $key): mixed { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1218034660); @@ -144,9 +139,8 @@ public function getData($key) * Returns true if $key is available. * * @param string $key - * @return boolean */ - public function hasKey($key) + public function hasKey(string $key): bool { return array_key_exists($key, $this->data); } @@ -155,11 +149,10 @@ public function hasKey($key) * Stores the given data under the given key in the session * * @param string $key The key under which the data should be stored - * @param object $data The data to be stored - * @return void + * @param mixed $data The data to be stored * @throws Exception\SessionNotStartedException */ - public function putData($key, $data) + public function putData(string $key, mixed $data): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1218034661); @@ -170,10 +163,9 @@ public function putData($key, $data) /** * Closes the session * - * @return void * @throws Exception\SessionNotStartedException */ - public function close() + public function close(): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1218034662); @@ -185,10 +177,9 @@ public function close() * Explicitly destroys all session data * * @param string $reason A reason for destroying the session – used by the LoggingAspect - * @return void * @throws Exception\SessionNotStartedException */ - public function destroy($reason = null) + public function destroy(string $reason = null): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1218034663); @@ -201,18 +192,15 @@ public function destroy($reason = null) * No operation for transient session. * * @param Bootstrap $bootstrap - * @return void */ - public static function destroyAll(Bootstrap $bootstrap) + public static function destroyAll(Bootstrap $bootstrap): void { } /** * No operation for transient session. - * - * @return void */ - public function collectGarbage() + public function collectGarbage(): void { } @@ -222,7 +210,7 @@ public function collectGarbage() * * @return integer unix timestamp */ - public function getLastActivityTimestamp() + public function getLastActivityTimestamp(): int { if ($this->lastActivityTimestamp === null) { $this->touch(); @@ -232,10 +220,8 @@ public function getLastActivityTimestamp() /** * Updates the last activity time to "now". - * - * @return void */ - public function touch() + public function touch(): void { $this->lastActivityTimestamp = time(); } @@ -247,12 +233,11 @@ public function touch() * recommended to use namespaced tags such as "Acme-Demo-MySpecialTag". * * @param string $tag The tag – must match be a valid cache frontend tag - * @return void * @throws Exception\SessionNotStartedException * @throws \InvalidArgumentException * @api */ - public function addTag($tag) + public function addTag(string $tag): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1422551048); @@ -264,11 +249,10 @@ public function addTag($tag) * Removes the specified tag from this session. * * @param string $tag The tag – must match be a valid cache frontend tag - * @return void * @throws Exception\SessionNotStartedException * @api */ - public function removeTag($tag) + public function removeTag(string $tag): void { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1422551049); @@ -281,11 +265,11 @@ public function removeTag($tag) /** * Returns the tags this session has been tagged with. * - * @return array The tags or an empty array if there aren't any + * @return string[] The tags or an empty array if there aren't any * @throws Exception\SessionNotStartedException * @api */ - public function getTags() + public function getTags(): array { if ($this->started !== true) { throw new Exception\SessionNotStartedException('The session has not been started yet.', 1422551050);