*
  • Shrike@irc.freenode.net:##php (decorator pattern demonstration)
  • *
  • f00li5h@irc.freenode.net:##php
  • * * Thank you for having shared your time and experience ! * @author James PIC * @copyright James PIC * @version 1.0 * @package Logger */ /** * Decarotar to Logging API. *

    This is a decorator class, this means that you should use it * when you instanciate a PEAR object.

    *

    For example :

    * * // used in {@inline eMail()} * $mail_object =& new LoggingDecorator( Mail::factory('mail') ); * $cool_object =& new LoggingDecorator( new Cool ); * // then objects can be used normally, pear errors will be redireted to Logger * * @author James PIC * @copyright James PIC * @version 1.0 * @uses Logger */ class Logger_Decorator { /** * The actual object to decorate with {@inline Logger}. * @access private * @var object */ private $o_decorated; public function __construct($o_decorated) { $this->o_decorated = $o_decorated; } public function __call($s_method, $a_arguments) { $ret = call_user_func_array(array($this->o_decorated, $s_method), $a_arguments); if($ret instanceof PEAR_Error) { $i = 0; while (!@strpos($ret->backtrace[$i]['file'], 'Decorator.php') && @$ret->backtrace[$i]['function'] != 'call_user_func_array') { $i++; } $a_last_event = $ret->backtrace[--$i]; LoggerBridge::GetInstance()->Log($a_arguments, $a_last_event['class'].'::'.$s_method, (int)@$a_last_event['line'], $ret->message, 'error', false); LoggerBridge::GetInstance()->ShowLog(); } return $ret; } } ?>