コード例 #1
0
 /**
  * Transforms the passed session instance into a JSON encoded string. If the data contains
  * objects, each of them will be serialized before store them to the persistence layer.
  *
  * @param \AppserverIo\Psr\Servlet\ServletSessionInterface $servletSession The session to be transformed
  *
  * @return string The JSON encoded session representation
  * @see \AppserverIo\Appserver\ServletEngine\SessionMarshaller::marshall()
  */
 public function marshall(ServletSessionInterface $servletSession)
 {
     // create the stdClass (that can easy be transformed into an JSON object)
     $stdClass = new \stdClass();
     // copy the values to the stdClass
     $stdClass->id = $servletSession->getId();
     $stdClass->name = $servletSession->getName();
     $stdClass->lifetime = $servletSession->getLifetime();
     $stdClass->maximumAge = $servletSession->getMaximumAge();
     $stdClass->domain = $servletSession->getDomain();
     $stdClass->path = $servletSession->getPath();
     $stdClass->secure = $servletSession->isSecure();
     $stdClass->httpOnly = $servletSession->isHttpOnly();
     // initialize the array for the session data
     $stdClass->data = array();
     // append the session data
     foreach (get_object_vars($servletSession->data) as $key => $value) {
         $stdClass->data[$key] = serialize($value);
     }
     // returns the JSON encoded session instance
     return json_encode($stdClass);
 }