forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSession.php
More file actions
46 lines (40 loc) · 1.23 KB
/
JSession.php
File metadata and controls
46 lines (40 loc) · 1.23 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;
function __construct($java){
$this->java=$java;
$this->serialID = uniqid("");
}
function __sleep() {
$session=java_get_session("PHPSESSION".session_id());
$session->put($this->serialID, $this->java);
return array("serialID");
}
function __wakeup() {
$session=java_get_session("PHPSESSION".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(!is_null($this->java)) return $this->java->__get($arg); }
function __set($key, $val) { if(!is_null($this->java)) return $this->java->__set($key, $val); }
function __call($m, $a) { if(!is_null($this->java)) return $this->java->__call($m,$a); }
function __toString() { if(!is_null($this->java)) return $this->java->__toString(); }
}
?>