-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Form Storage for getting and setting data depending on form session Update session storage contract Add infection tests Update tests
- Loading branch information
Showing
16 changed files
with
152 additions
and
154 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lexal\SteppedForm\Form\Storage; | ||
|
||
use Lexal\SteppedForm\Exception\ReadSessionKeyException; | ||
|
||
final class FormStorage implements FormStorageInterface | ||
{ | ||
private const STORAGE_KEY = '__CURRENT_SESSION_KEY__'; | ||
|
||
public function __construct( | ||
private readonly StorageInterface $storage, | ||
private readonly SessionStorageInterface $sessionStorage = new NullSessionStorage(), | ||
) { | ||
} | ||
|
||
public function setCurrentSession(string $sessionKey): void | ||
{ | ||
$this->sessionStorage->put(self::STORAGE_KEY, $sessionKey); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @throws ReadSessionKeyException | ||
*/ | ||
public function get(string $key, mixed $default = null): mixed | ||
{ | ||
return $this->storage->get($key, $this->getCurrentSession(), $default); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @throws ReadSessionKeyException | ||
*/ | ||
public function put(string $key, mixed $data): void | ||
{ | ||
$this->storage->put($key, $this->getCurrentSession(), $data); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @throws ReadSessionKeyException | ||
*/ | ||
public function clear(): void | ||
{ | ||
$this->storage->clear($this->getCurrentSession()); | ||
} | ||
|
||
/** | ||
* @throws ReadSessionKeyException | ||
*/ | ||
private function getCurrentSession(): string | ||
{ | ||
return $this->sessionStorage->get(self::STORAGE_KEY) ?? self::DEFAULT_SESSION_KEY; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lexal\SteppedForm\Form\Storage; | ||
|
||
interface FormStorageInterface | ||
{ | ||
public const DEFAULT_SESSION_KEY = '__MAIN__'; | ||
|
||
/** | ||
* Sets current session key for the form. | ||
*/ | ||
public function setCurrentSession(string $sessionKey): void; | ||
|
||
/** | ||
* Returns data from the form storage by key. | ||
*/ | ||
public function get(string $key, mixed $default = null): mixed; | ||
|
||
/** | ||
* Sets data to the form storage. | ||
*/ | ||
public function put(string $key, mixed $data): void; | ||
|
||
/** | ||
* Removes all form data from the storage. | ||
*/ | ||
public function clear(): void; | ||
} |
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
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
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
Oops, something went wrong.