diff --git a/composer.json b/composer.json index 9376a6c..9ee0b15 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": ">=7.1", "nette/di": "^3.0-RC1@dev", - "nette/http": "^3.0@dev" + "nette/http": "^3.1.6" }, "require-dev": { "nette/utils": "^3.0@dev", diff --git a/src/SessionSection.php b/src/SessionSection.php index b23c9ed..d4c941e 100644 --- a/src/SessionSection.php +++ b/src/SessionSection.php @@ -33,19 +33,30 @@ public function getIterator(): Iterator return new ArrayIterator($this->data); } - /** - * @param string $name - * @param mixed $value - */ + + /** @param mixed $value */ + public function set(string $name, $value, ?string $expiration = NULL): void + { + if ($value === NULL) { + $this->remove($name); + } else { + $this->__set($name, $value); + } + } + + /** @return mixed */ + public function get(string $name) + { + return $this->__get($name); + } + + /** @param mixed $value */ public function __set(string $name, $value): void { $this->data[$name] = $value; } - /** - * @param string $name - * @return mixed - */ + /** @return mixed */ public function &__get(string $name) { if ($this->warnOnUndefined && !array_key_exists($name, $this->data)) { @@ -62,7 +73,7 @@ public function __isset(string $name): bool public function __unset(string $name): void { - unset($this->data[$name]); + $this->remove($name); } /** @@ -82,9 +93,16 @@ public function removeExpiration($variables = NULL): void { } - public function remove(): void + /** @param string|string[]|null $name */ + public function remove($name = null): void { - $this->data = []; + if ($name !== NULL) { + foreach ((array) $name as $name) { + unset($this->data[$name]); + } + } else { + $this->data = []; + } } }