Example #1
0
 /**
  * @param string|null $id
  * @return string
  * @throws SessionException
  */
 public function start(string $id = null) : string
 {
     // Check if session has already been started
     if ($this->session instanceof ComelySession) {
         throw SessionException::sessionExists();
     }
     // Read Session
     $sessionId = $id ?? $_COOKIE["COMELYSESSID"] ?? null;
     if (isset($sessionId)) {
         // Session ID found, attempt to read
         $this->resume($sessionId);
     }
     // Check if we got ComelySession from read
     if (!$this->session instanceof ComelySession) {
         $this->create();
     }
     // Register shutdown handler
     register_shutdown_function([$this, "write"]);
     // Save cookie
     $this->sessionCookie($this->session->getId());
     // Return session Id
     return $this->session->getId();
 }