Go to the documentation of this file.00001 <?php
00002
00017 class Services_Yadis_PHPSession {
00024 function set($name, $value)
00025 {
00026 $_SESSION[$name] = $value;
00027 }
00028
00038 function get($name, $default=null)
00039 {
00040 if (array_key_exists($name, $_SESSION)) {
00041 return $_SESSION[$name];
00042 } else {
00043 return $default;
00044 }
00045 }
00046
00052 function del($name)
00053 {
00054 unset($_SESSION[$name]);
00055 }
00056 }
00057
00066 class Services_Yadis_Manager {
00067
00073 function Services_Yadis_Manager($starting_url, $yadis_url,
00074 $services, $session_key)
00075 {
00076
00077 $this->starting_url = $starting_url;
00078
00079
00080 $this->yadis_url = $yadis_url;
00081
00082
00083 $this->services = $services;
00084
00085 $this->session_key = $session_key;
00086
00087
00088 $this->_current = null;
00089
00090
00091 $this->stale = false;
00092 }
00093
00097 function length()
00098 {
00099
00100 return count($this->services);
00101 }
00102
00109 function nextService()
00110 {
00111
00112 if ($this->services) {
00113 $this->_current = array_shift($this->services);
00114 } else {
00115 $this->_current = null;
00116 }
00117
00118 return $this->_current;
00119 }
00120
00124 function current()
00125 {
00126
00127
00128 return $this->_current;
00129 }
00130
00134 function forURL($url)
00135 {
00136 return in_array($url, array($this->starting_url, $this->yadis_url));
00137 }
00138
00142 function started()
00143 {
00144
00145 return $this->_current !== null;
00146 }
00147 }
00148
00159 class Services_Yadis_Discovery {
00160
00164 var $DEFAULT_SUFFIX = 'auth';
00165
00169 var $PREFIX = '_yadis_services_';
00170
00180 function Services_Yadis_Discovery(&$session, $url,
00181 $session_key_suffix = null)
00182 {
00184 $this->session =& $session;
00185 $this->url = $url;
00186 if ($session_key_suffix === null) {
00187 $session_key_suffix = $this->DEFAULT_SUFFIX;
00188 }
00189
00190 $this->session_key_suffix = $session_key_suffix;
00191 $this->session_key = $this->PREFIX . $this->session_key_suffix;
00192 }
00193
00198 function getNextService($discover_cb, &$fetcher)
00199 {
00200 $manager = $this->getManager();
00201 if ((!$manager) ||
00202 $manager->stale) {
00203 $this->destroyManager();
00204 $http_response = array();
00205
00206 $services = call_user_func($discover_cb, $this->url,
00207 $fetcher);
00208
00209 $manager = $this->createManager($services, $this->url);
00210 }
00211
00212 if ($manager) {
00213 $service = $manager->nextService();
00214 $this->session->set($this->session_key, serialize($manager));
00215 } else {
00216 $service = null;
00217 }
00218
00219 return $service;
00220 }
00221
00227 function cleanup()
00228 {
00229 $manager = $this->getManager();
00230 if ($manager) {
00231 $service = $manager->current();
00232 $this->destroyManager();
00233 } else {
00234 $service = null;
00235 }
00236
00237 return $service;
00238 }
00239
00243 function getSessionKey()
00244 {
00245
00246 return $this->PREFIX . $this->session_key_suffix;
00247 }
00248
00252 function getManager()
00253 {
00254
00255
00256
00257 $manager_str = $this->session->get($this->getSessionKey());
00258 $manager = null;
00259
00260 if ($manager_str !== null) {
00261 $manager = unserialize($manager_str);
00262 }
00263
00264 if ($manager && $manager->forURL($this->url)) {
00265 return $manager;
00266 } else {
00267 return null;
00268 }
00269 }
00270
00274 function &createManager($services, $yadis_url = null)
00275 {
00276 $key = $this->getSessionKey();
00277 if ($this->getManager()) {
00278 return $this->getManager();
00279 }
00280
00281 if (!$services) {
00282 return null;
00283 }
00284
00285 $manager = new Services_Yadis_Manager($this->url, $yadis_url,
00286 $services, $key);
00287 $this->session->set($this->session_key, serialize($manager));
00288 return $manager;
00289 }
00290
00294 function destroyManager()
00295 {
00296 if ($this->getManager() !== null) {
00297 $key = $this->getSessionKey();
00298 $this->session->del($key);
00299 }
00300 }
00301 }
00302
00303 ?>