예제 #1
0
 /**
  * Saves the passed session to the persistence layer.
  *
  * @param \AppserverIo\Psr\Servlet\ServletSessionInterface $session The session to save
  *
  * @return void
  * @throws AppserverIo\Appserver\ServletEngine\SessionCanNotBeSavedException Is thrown if the session can't be saved
  */
 public function save(ServletSessionInterface $session)
 {
     // don't save the session if it has been destroyed
     if ($session->getId() == null) {
         return;
     }
     // update the checksum and the file that stores the session data
     if (apc_store($session->getId(), $this->marshall($session)) === false) {
         throw new SessionCanNotBeSavedException(sprintf('Session with ID %s can\'t be saved'));
     }
 }
 /**
  * Initializes the session instance from the passed JSON string. If the encoded
  * data contains objects, they will be un-serialized before reattached to the
  * session instance.
  *
  * @param \AppserverIo\Psr\Servlet\ServletSessionInterface $servletSession The empty session instance we want the un-marshaled data be added to
  * @param string                                           $marshalled     The marshaled session representation
  *
  * @return \AppserverIo\Psr\Servlet\ServletSessionInterface The decoded session instance
  * @see \AppserverIo\Appserver\ServletEngine\SessionMarshaller::unmarshall()
  */
 public function unmarshall(ServletSessionInterface $servletSession, $marshalled)
 {
     // decode the string
     $decodedSession = json_decode($marshalled);
     // extract the values
     $id = $decodedSession->id;
     $name = $decodedSession->name;
     $lifetime = $decodedSession->lifetime;
     $maximumAge = $decodedSession->maximumAge;
     $domain = $decodedSession->domain;
     $path = $decodedSession->path;
     $secure = $decodedSession->secure;
     $httpOnly = $decodedSession->httpOnly;
     $data = $decodedSession->data;
     // initialize the instance
     $servletSession->init($id, $name, $lifetime, $maximumAge, $domain, $path, $secure, $httpOnly);
     // append the session data
     foreach ($data as $key => $value) {
         $servletSession->putData($key, unserialize($value));
     }
 }
 /**
  * Attaches the passed session to the manager and returns the instance.
  * If a session
  * with the session identifier already exists, it will be overwritten.
  *
  * @param \AppserverIo\Psr\Servlet\ServletSessionInterface $session The session to attach
  *
  * @return void
  */
 public function attach(ServletSessionInterface $session)
 {
     // load session ID
     $id = $session->getId();
     // register checksum + session
     $this->getSessions()->set($id, $session);
 }
 /**
  * Saves the passed session to the persistence layer.
  *
  * @param \AppserverIo\Psr\Servlet\ServletSessionInterface $session The session to save
  *
  * @return void
  * @throws AppserverIo\Appserver\ServletEngine\SessionCanNotBeSavedException Is thrown if the session can't be saved
  */
 public function save(ServletSessionInterface $session)
 {
     // don't save the session if it has been destroyed
     if ($session->getId() == null) {
         return;
     }
     // prepare the session filename
     $sessionFilename = $this->getSessionSavePath($this->getSessionSettings()->getSessionFilePrefix() . $session->getId());
     // update the checksum and the file that stores the session data
     if (file_put_contents($sessionFilename, $this->marshall($session)) === false) {
         throw new SessionCanNotBeSavedException(sprintf('Session with ID %s can\'t be saved'));
     }
 }