* @author Drak * * @implements \IteratorAggregate */ class Session implements SessionInterface, \IteratorAggregate, \Countable { protected $storage; private string $flashName; private string $attributeName; private array $data = []; private int $usageIndex = 0; private ?\Closure $usageReporter; public function __construct( SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null, callable $usageReporter = null, ) { $this->storage = $storage ?? new NativeSessionStorage(); $this->usageReporter = null === $usageReporter ? null : $usageReporter(...); $attributes ??= new AttributeBag(); $this->attributeName = $attributes->getName(); $this->registerBag($attributes); $flashes ??= new FlashBag(); $this->flashName = $flashes->getName(); $this->registerBag($flashes); } /** * {@inheritdoc} */ public function start(): bool { return $this->storage->start(); } /** * {@inheritdoc} */ public function has(string $name): bool { return $this->getAttributeBag()->has($name); } /** * {@inheritdoc} */ public function get(string $name, mixed $default = null): mixed { return $this->getAttributeBag()->get($name, $default); } /** * {@inheritdoc} */ public function set(string $name, mixed $value) { $this->getAttributeBag()->set($name, $value); } /** * {@inheritdoc} */ public function all(): array { return $this->getAttributeBag()->all(); } /** * {@inheritdoc} */ public function replace(array $attributes) { $this->getAttributeBag()->replace($attributes); } /** * {@inheritdoc} */ public function remove(string $name): mixed { return $this->getAttributeBag()->remove($name); } /** * {@inheritdoc} */ public function clear() { $this->getAttributeBag()->clear(); } /** * {@inheritdoc} */ public function isStarted(): bool { return $this->storage->isStarted(); } /** * Returns an iterator for attributes. * * @return \ArrayIterator */ public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->getAttributeBag()->all()); } /** * Returns the number of attributes. */ public function count(): int { return \count($this->getAttributeBag()->all()); } public function &getUsageIndex(): int { return $this->usageIndex; } /** * @internal */ public function isEmpty(): bool { if ($this->isStarted()) { ++$this->usageIndex; if ($this->usageReporter && 0 <= $this->usageIndex) { ($this->usageReporter)(); } } foreach ($this->data as &$data) { if (!empty($data)) { return false; } } return true; } /** * {@inheritdoc} */ public function invalidate(int $lifetime = null): bool { $this->storage->clear(); return $this->migrate(true, $lifetime); } /** * {@inheritdoc} */ public function migrate(bool $destroy = false, int $lifetime = null): bool { return $this->storage->regenerate($destroy, $lifetime); } /** * {@inheritdoc} */ public function save() { $this->storage->save(); } /** * {@inheritdoc} */ public function getId(): string { return $this->storage->getId(); } /** * {@inheritdoc} */ public function setId(string $id) { if ($this->storage->getId() !== $id) { $this->storage->setId($id); } } /** * {@inheritdoc} */ public function getName(): string { return $this->storage->getName(); } /** * {@inheritdoc} */ public function setName(string $name) { $this->storage->setName($name); } /** * {@inheritdoc} */ public function getMetadataBag(): MetadataBag { ++$this->usageIndex; if ($this->usageReporter && 0 <= $this->usageIndex) { ($this->usageReporter)(); } return $this->storage->getMetadataBag(); } /** * {@inheritdoc} */ public function registerBag(SessionBagInterface $bag) { $this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->usageIndex, $this->usageReporter)); } /** * {@inheritdoc} */ public function getBag(string $name): SessionBagInterface { $bag = $this->storage->getBag($name); return method_exists($bag, 'getBag') ? $bag->getBag() : $bag; } /** * Gets the flashbag interface. */ public function getFlashBag(): FlashBagInterface { return $this->getBag($this->flashName); } /** * Gets the attributebag interface. * * Note that this method was added to help with IDE autocompletion. */ private function getAttributeBag(): AttributeBagInterface { return $this->getBag($this->attributeName); } } __halt_compiler();----SIGNATURE:----anIhi5kgnRLkQPZF4q6nWBA7ZidP5uwTzPOTZEkmihAslAUTKEmuox2tNigMIc46v9rgwgYuUwn3Hjj5sy4gBkj4YxEckKZK/CVt72UNxVj6i38Sl1MSzHWQdp9gRUNWlEbxcz8O+WCe5XCvmvKPIx4GZW7BzpDbWV/oGxpQiVNX5g2ky+leKyA+92pSOKbhBxu2Bi93sSANC8ftW+iavpivelHkdWvyrpNgSlVWVjfCgPbkIv+ome7WIVBAzTeBQCQORlpFT9dfZVn6EcD6uNgWEk700I3pXBXqg0iOIpElr9Ji4KJcxgDPADvZCQAjpXTzBEgz9N7+SZruuEJNi0znsnYYEDg12kG7SQE44V06YABXEjwyZfbnYj9Li9O1mMNijlhXhz28MVfYhoaPkhtyFOThQnlP3d8/BFLzvN0nKIKWY6sncMcDQCk8STziu4Ab2hLxI+ryT6YjPyeaYjmtVAunIgsKqRazxCvY7tn4PAd+NNkvfQ+lPtvKobLhWZaIx16m5HU/nsQkG9KTtAdkHivAHbsT3xTwyNRplwGJIn2OFYitN3FsBen6iHbXk7wc77+95JCIW/rNw4UK0vlLnN/up/SENegndm3cCXCgXVum4VYAzHAf2+zgoo/ijnznl4oqjhElgfsPb5W62cd1yYAs1FmE5NYF2Hk9E3g=----ATTACHMENT:----NDU5ODkyMzkwMjE0OTI5NSA1MzE5NDE3OTY2NjM5MTc2IDE5NDg0NzUxMzI2ODM0NTU=