| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui; |
| 6: | |
| 7: | use Atk4\Core\TraitUtil; |
| 8: | |
| 9: | trait SessionTrait |
| 10: | { |
| 11: | private function getSessionManager(): App\SessionManager |
| 12: | { |
| 13: | |
| 14: | if (!TraitUtil::hasNameTrait($this)) { |
| 15: | throw new Exception('Object must have NameTrait applied to use session'); |
| 16: | } |
| 17: | |
| 18: | return $this->getApp()->session; |
| 19: | } |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | public function atomicSession(\Closure $fx, bool $readAndCloseImmediately = false) |
| 29: | { |
| 30: | return $this->getSessionManager()->atomicSession($fx, $readAndCloseImmediately); |
| 31: | } |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | public function memorize(string $key, $value) |
| 41: | { |
| 42: | return $this->getSessionManager()->memorize($this->name, $key, $value); |
| 43: | } |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | public function learn(string $key, $defaultValue = null) |
| 53: | { |
| 54: | return $this->getSessionManager()->learn($this->name, $key, $defaultValue); |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | public function recall(string $key, $defaultValue = null) |
| 66: | { |
| 67: | return $this->getSessionManager()->recall($this->name, $key, $defaultValue); |
| 68: | } |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | public function forget(string $key = null) |
| 77: | { |
| 78: | $this->getSessionManager()->forget($this->name, $key); |
| 79: | |
| 80: | return $this; |
| 81: | } |
| 82: | } |
| 83: | |