Пример #1
0
 function &createSession($create = TRUE)
 {
     if (ServletContext::validClass($this->context)) {
         $response =& $this->context->getServletResponse();
         $session =& $this->context->getServletSession();
         if (IHttpResponse::validClass($response) && IHttpSession::validClass($session)) {
             $sessionid = '';
             $cookie = $this->getCookie('_JPHPSESSIONID');
             if (!isset($cookie)) {
                 $sessionid = $this->getParameter('_JPHPSESSIONID');
             } else {
                 $sessionid = $cookie->getValue();
             }
             if (strlen(trim($sessionid)) < 8) {
                 if ($create == FALSE) {
                     return NULL;
                 } else {
                     $sessionid = md5(StringBuffer::generateKey(16));
                 }
             }
             $session->setSessionID($sessionid);
             $session->initialize();
             $cookie = new Cookie('_JPHPSESSIONID', $sessionid);
             if ($session->getMaxInactiveInterval() > 0) {
                 $cookie->setMaxAge(time() + $session->getMaxInactiveInterval());
             } else {
                 $cookie->setMaxAge(0);
             }
             $response->addCookie($cookie);
             return $session;
         }
     }
     return NULL;
 }
Пример #2
0
 function HttpServletContext(&$servletcontext)
 {
     parent::HttpContext();
     if (ServletContext::validClass($servletcontext)) {
         $this->context =& $servletcontext;
     }
 }
Пример #3
0
 function ServletContext($web_xml_file)
 {
     $web_xml_file = new File($web_xml_file);
     if (File::validClass($web_xml_file) && $web_xml_file->exists()) {
         $this->file =& $web_xml_file;
         $cache_file = new File($web_xml_file->getFilePath() . 'cached');
         $valid_cache = FALSE;
         if ($cache_file->exists() && $web_xml_file->lastModified() == $cache_file->lastModified()) {
             $this->config = @unserialize(FileReader::readFileContent($cache_file));
             if (ServletContext::validClass($this->config)) {
                 $valid_cache = TRUE;
             }
         }
         if (!$valid_cache) {
             $this->config =& ServletXMLConfigReader::readXMLConfig(new FileReader($web_xml_file));
             FileWriter::writeToFile($cache_file, serialize($this->config), $web_xml_file->lastModified());
         }
     }
     if (isset($this->config)) {
         $this->initServletContext();
     }
 }