Example #1
0
 /**
  * Change current Session Handler
  *
  * @param string|Next\Session\Handlers\Handler $handler
  *   Handler Object or Handler Name
  *
  * @throws Next\Session\Handlers\HandlerException
  *   Changing Session Handler to a invalid Handler, characterized as
  *   instance of Next\Session\Hndlers\Handler
  */
 public function changeHandler($handler)
 {
     // If we don't have a true Handler...
     if (!$handler instanceof Handler) {
         // ... let's find an assigned Handler that matches given string
         $test = $this->handlers->find($handler);
         // Nothing Found?
         if (!$test instanceof Handler) {
             throw HandlersException::unknownHandler((string) $handler);
         }
         // Yeah! We're ninjas!
         $handler = $test;
     }
     // Committing Session
     $this->session->commit();
     // Setting Session Options with Handler Options
     if (isset($handler->getOptions->savePath)) {
         $this->session->setSessionSavePath($handler->getOptions->savePath);
     }
     $lifetime = isset($handler->getOptions->lifetime) ? $handler->getOptions->lifetime : 0;
     if ($lifetime > 0) {
         $this->session->setSessionLifetime($lifetime);
     }
     // Changing current Session Handler
     $this->handler =& $handler;
     // Restarting Session
     $this->session->init($this->session->getSessionName(), $this->session->getSessionID());
 }