<commit_before><?php
	declare(strict_types = 1);

	namespace Edde\Common\Session;

	use Edde\Api\Session\ISession;
	use Edde\Api\Session\ISessionManager;
	use Edde\Api\Session\SessionException;
	use Edde\Common\Usable\AbstractUsable;

	class SessionManager extends AbstractUsable implements ISessionManager {
		/**
		 * @var string
		 */
		protected $namespace;

		protected $sessionId;
		/**
		 * @var ISession[]
		 */
		protected $sessionList = [];

		/**
		 * @param string $namespace
		 */
		public function __construct($namespace = null) {
			$this->namespace = $namespace ?: 'edde';
		}

		public function start(string $sessionId = null): ISessionManager {
			if ($this->isSession()) {
				return $this;
			}
			if ($this->sessionId !== null) {
				$this->setSessionId($sessionId);
			}
			if ($this->sessionId !== null) {
				session_id($this->sessionId);
			}
			session_start();
			return $this;
		}

		public function isSession(): bool {
			return session_status() === PHP_SESSION_ACTIVE;
		}

		public function setSessionId(string $sessionId = null): ISessionManager {
			$this->sessionId = $sessionId;
			return $this;
		}

		public function getSession(string $name): ISession {
			return $this->sessionList[$name] ?? $this->sessionList[$name] = new Session($this, $name);
		}

		public function &session(string $name): array {
			$this->use();
			$_SESSION[$this->namespace] = $_SESSION[$this->namespace] ?? [];
			$_SESSION[$this->namespace][$name] = $_SESSION[$this->namespace][$name] ?? [];
			return $_SESSION[$this->namespace][$name];
		}

		public function close(): ISessionManager {
			if ($this->isSession() === false) {
				throw new SessionException('Session is not running; there is nothing to close.');<commit_msg>- oops, session was not started in ::session method<commit_after><?php
	declare(strict_types = 1);

	namespace Edde\Common\Session;

	use Edde\Api\Session\ISession;
	use Edde\Api\Session\ISessionManager;
	use Edde\Api\Session\SessionException;
	use Edde\Common\Usable\AbstractUsable;

	class SessionManager extends AbstractUsable implements ISessionManager {
		/**
		 * @var string
		 */
		protected $namespace;

		protected $sessionId;
		/**
		 * @var ISession[]
		 */
		protected $sessionList = [];

		/**
		 * @param string $namespace
		 */
		public function __construct($namespace = null) {
			$this->namespace = $namespace ?: 'edde';
		}

		public function getSession(string $name): ISession {
			return $this->sessionList[$name] ?? $this->sessionList[$name] = new Session($this, $name);
		}

		public function &session(string $name): array {
			$this->use();
			$this->start();
			$_SESSION[$this->namespace] = $_SESSION[$this->namespace] ?? [];
			$_SESSION[$this->namespace][$name] = $_SESSION[$this->namespace][$name] ?? [];
			return $_SESSION[$this->namespace][$name];
		}

		public function start(string $sessionId = null): ISessionManager {
			if ($this->isSession()) {
				return $this;
			}
			if ($this->sessionId !== null) {
				$this->setSessionId($sessionId);
			}
			if ($this->sessionId !== null) {
				session_id($this->sessionId);
			}
			session_start();
			return $this;
		}

		public function isSession(): bool {
			return session_status() === PHP_SESSION_ACTIVE;
		}

		public function setSessionId(string $sessionId = null): ISessionManager {
			$this->sessionId = $sessionId;
			return $this;
		}

		public function close(): ISessionManager {
			if ($this->isSession() === false) {
				throw new SessionException('Session is not running; there is nothing to close.');
{'fraction_non_alphanumeric': 0.15785007072135784, 'fraction_numerical': 0.0005657708628005657, 'mean_word_length': 3.9593267882187937, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '401759', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1063, 'n_words': 244}