Menu

[r322]: / trunk / php-java-bridge / php_java_lib / JSession.php  Maximize  Restore  History

Download this file

47 lines (40 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* The JSessionAdapter makes it possible to store java values into the
* $_SESSION variable.
*
* Example:
* $vector = new JSessionAdapter(new Java("java.util.Vector"));
* $vector->addElement(...);
* $_SESSION["v"]=$vector;
*/
class JSessionProxy {
var $java;
var $serialID=0;
function __construct($java){
$this->java=$java;
$this->serialID++;
}
function __sleep() {
$session=java_get_session("ser".session_id());
$session->put($this->serialID, $this->java);
return array("serialID");
}
function __wakeup() {
$session=java_get_session("ser".session_id());
$this->java = $session->get($this->serialID);
}
function getJava() {
return $this->java;
}
function __destruct() {
if($this->java) return $this->java->__destruct();
}
}
class JSessionAdapter extends JSessionProxy {
function __get($arg) { if($this->java) return $this->java->__get($arg); }
function __put($key, $val) { if($this->java) return $this->java->__put($key, $val); }
function __call($m, $a) { if($this->java) return $this->java->__call($m,$a); }
function __toString() { if($this->java) return $this->java->__toString(); }
}
?>