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

TASK: Add parameter and return types to Session, TransientSession and SessionInterface #14

Closed
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
60 changes: 24 additions & 36 deletions Neos.Flow/Classes/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'];
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -266,20 +263,19 @@ 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;
}

/**
* 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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
}
Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
36 changes: 18 additions & 18 deletions Neos.Flow/Classes/Session/SessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ 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.
*
* @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
Expand All @@ -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.
Expand All @@ -69,15 +69,15 @@ 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.
*
* @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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -111,24 +111,24 @@ 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".
*
* @return void
* @api
*/
public function touch();
public function touch(): void;

/**
* Returns the unix time stamp marking the last point in time this session has
Expand All @@ -140,15 +140,15 @@ public function touch();
* @return integer unix timestamp
* @api
*/
public function getLastActivityTimestamp();
public function getLastActivityTimestamp(): int;

/**
* Explicitly writes (persists) and closes the session
*
* @return void
* @throws Exception\SessionNotStartedException
*/
public function close();
public function close(): void;

/**
* Explicitly destroys all session data
Expand All @@ -157,5 +157,5 @@ public function close();
* @return void
* @throws Exception\SessionNotStartedException
*/
public function destroy($reason = null);
public function destroy(string $reason = null): void;
}
Loading
Loading