cvs: pear /LiveUser/docs/examples/example1 example.php

From: Date: Sun, 12 Dec 2004 21:45:04 +0000
Subject: cvs: pear /LiveUser/docs/examples/example1 example.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-27262@lists.php.net to get a copy of this message
arnaud Sun Dec 12 16:45:04 2004 EDT Modified files: /pear/LiveUser/docs/examples/example1 example.php Log: adding observer code http://cvs.php.net/diff.php/pear/LiveUser/docs/examples/example1/example.php?r1=1.1&r2=1.2&ty=u Index: pear/LiveUser/docs/examples/example1/example.php diff -u pear/LiveUser/docs/examples/example1/example.php:1.1 pear/LiveUser/docs/examples/example1/example.php:1.2 --- pear/LiveUser/docs/examples/example1/example.php:1.1 Sat Nov 13 13:14:22 2004 +++ pear/LiveUser/docs/examples/example1/example.php Sun Dec 12 16:45:03 2004 @@ -12,12 +12,13 @@ * No permission management is supported. * * @author Björn Kraus <krausbn@php.net> - * @version $Id: example.php,v 1.1 2004/11/13 18:14:22 arnaud Exp $ + * @version $Id: example.php,v 1.2 2004/12/12 21:45:03 arnaud Exp $ **/ error_reporting(E_ALL); // Get LiveUser configuration array require_once 'conf.php'; +require 'Log.php'; if ($xml_is_readable == false || $xml_is_writable == false) { die('<p style="color: red; text-align: center;">The XML file isn\'t readable/writable. Add the right permissions to it and then try again.</p>'); @@ -32,13 +33,80 @@ echo('<hr /><span style="color: red">' . $errObj->getMessage() . ':<br />'. $errObj->getUserinfo() . '</span><hr />'); } +$GLOBALS['obs'] = ''; + +/** + * LiveUser observer example. + * + * This class uses the facilities provided by PEAR::Log + * to create an observer for LiveUser. + * + * There are two ways to define an observer: + * - The class should contain methods + * with the same names ar the events that can be triggered. + * - when the observer is attached to LiveUser you must define + * the event => methodName mapping. + * + * @access public + * @param object receives the main LiveUser object, fetch it by reference + * to avoid object copies + * @param array an array of optional paramaters the triggered event can send + * @return void return is discarded + */ +class Log_LU extends Log +{ + function Log_LU($name = '', $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (!empty($conf['error_prepend'])) { + $this->_error_prepend = $conf['error_prepend']; + } else { + $this->_error_prepend = ini_get('error_prepend_string'); + } + + if (!empty($conf['error_append'])) { + $this->_error_append = $conf['error_append']; + } else { + $this->_error_append = ini_get('error_append_string'); + } + } + function onLogin(&$obj, $params = array()) + { + $GLOBALS['obs'] .= '<p>Observer called with the Liveuser object'; + if (count($params) > 0) { + $GLOBALS['obs'] .= ' and optional parameters</p>'; + ob_start(); + var_dump($params); + $GLOBALS['obs'] .= ob_get_contents(); + ob_clean(); + } + } + function onLogout() + { + print 'You have been logged out'; + exit(); + } + function onIdled() + { + print 'You have been idle for too long !<br />'; + print 'Please login again'; + } +} + +$log = &Log::factory('LU'); + // Create new LiveUser (LiveUser) object. // We´ll only use the auth container, permissions are not used. $LU =& LiveUser::factory($liveuserConfig); +$LU->attachObserverObj($log); $username = (isset($_REQUEST['handle'])) ? $_REQUEST['handle'] : NULL; $password = (isset($_REQUEST['passwd'])) ? $_REQUEST['passwd'] : NULL; -$logout = (isset($_REQUEST['logout'])) ? $_REQUEST['logout'] : FALSE; +$logout = (isset($_REQUEST['logout'])) ? $_REQUEST['logout'] : false; $LU->init($username, $password, $logout); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> @@ -172,7 +240,10 @@ print_r($_SESSION); echo '<hr />'; print_r($_REQUEST); +echo '<hr />'; +echo 'Observer<br />'; +var_dump($GLOBALS['obs']); echo '</pre>'; ?> </body> -</html> \ No newline at end of file +</html>

« previous php.pear.cvs (#27262) next »