Code

6abc73ae5e181a9b5083e72369a5bf7e88013dd4
[gosa.git] / gosa-core / include / class_remoteObject.inc
1 <?php
3 class remoteObject
4 {
5     private $rpcHandle;
6     private $properties;
7     private $methods;
8     private $type;
9     private $object_id;
10     private $ref_id;
11     private $values;
13     private $cache = array();
15     function __construct(&$rpcHandle, $type, $properties, $values, $methods, $object_id, $ref_id)
16     {
17         $this->rpcHandle = $rpcHandle;
18         $this->properties = $properties;
19         $this->methods = $methods;
20         $this->type = $type;
21         $this->ref_id = $ref_id;
22         $this->object_id = $object_id;
23         $this->values = $values;
24         $this->cache = $values;
25     }
28     function getType()
29     {
30         return($this->type);
31     }
32     
33     function getProperties()
34     {
35         return($this->properties);
36     }
37     
38     function getReferenceId()
39     {
40         return($this->red_id);
41     }
42    
43     function clearCache()
44     {
45         $this->__clearCache();
46     }
47  
49     // Enables calls like  get_property() and set_property()
50     //  and allow to call the dynamic methods
51     function __call($name, $args)
52     {
53         // Check if such an attribute is registered
54         if(preg_match("/^get_/", $name)){
55             $varName = preg_replace("/^get_/","", $name);
56             if(in_array_strict($varName, $this->properties)){
57                 $force = isset($args[0]) && $args[0];
58                 return($this->__getProperty($varName, $force));
59             } 
60         }elseif(preg_match("/^set_/", $name)){
61             $varName = preg_replace("/^set_/","", $name);
62             if(in_array_strict($varName, $this->properties)){
63                 return($this->__setProperty($varName, $args[0]));
64             }
65         }
67         echo "<br><b>Calling: {$name}</b>";
68         #return($this->rpcHandle->$name($args));
69     }
72     // Enables calls like  $object->mailAddress = 'test';
73     function __set($varName, $value)
74     {
75         // Set property value
76         if(in_array_strict($varName, $this->properties)){
77             return($this->__setProperty($varName, $value));
78         }
80         // Set class member value
81         if(isset($this->$varName)){
82             $this->$varName = $value;
83             return(TRUE);
84         }
86         trigger_error("No attribute '{$varName}' defined!");
87         return(FALSE);
88     }
91     function __get($varName)
92     {
93         if(in_array_strict($varName, $this->properties)){
94             return($this->__getProperty($varName));
95         }
97         // Set class member value
98         if(isset($this->$varName)){
99             return($this->$varName);
100         }
102         trigger_error("No attribute '{$varName}' defined!");
103         return(NULL);
104     }
106     
107     function __setProperty($name, $value)
108     {
109         $this->rpcHandle->setObjectProperty($this->ref_id, $name,$value);
110         if($this->rpcHandle->success()){
111             $this->__addPropValueToCache($name, $value);
112             return(TRUE);
113         }
114         return(FALSE);
115     }
118     function __getProperty($name, $force = FALSE)
119     {
120         if(!$force && $this->__propIsCached($name)){
121             return($this->__getPropFromCache($name));
122         }
124         $res = $this->rpcHandle->getObjectProperty($this->ref_id, $name);
125         if(!$this->rpcHandle->success()){
126             return(NULL);
127         }else{
128             $this->__addPropValueToCache($name, $res);
129             return($res);
130         }
131     }
133     
134     function close()
135     {
136         $res = $this->rpcHandle->closeObject($this->ref_id);
137         if($this->success){
138             $this->ref_id = "";
139         }
140         return($this->rpcHandle->success());
141     }
143     
144     function __addPropValueToCache($name, $value)
145     {
146         $this->cache[$name] = $value;
147     }
149     function __getPropFromCache($name)
150     {
151         return($this->cache[$name]);
152     }
154     function __propIsCached($name)
155     {
156         return(isset($this->cache[$name]));
157     }
159     function __clearCache()
160     {
161         $this->cache = array();
162     }
164     function __removePropFromCache($name)
165     {
166         if($this->__propIsCached($name)){
167             unset($this->cache[$name]);
168         }
169     }
172 ?>