/** * Class ErrorLogger */ class ErrorLogger extends Logger { /** * @param $message * @return mixed|void */ protected function doLog($message) { echo "Sending to stderr: ", $message, " \n"; } } /** * Class StdoutLogger */ class StdoutLogger extends Logger { /** * @param $message * @return mixed|void */ protected function doLog($message) { echo "Writing to stdout: ", $message, " \n"; } } $logger = new StdoutLogger(); $logger->setNext(new ErrorLogger())->setNext(new EmailLogger()); $logger->log('Something happened');
<?php header('Content-Type: text/html; charset=utf-8'); require 'Logger.php'; require 'EmailLogger.php'; require 'ErrorLogger.php'; require 'StdoutLogger.php'; $logger = new StdoutLogger(); $logger->setNext(new ErrorLogger())->setNext(new EmailLogger()); $logger->log('Quelque chose se passe !');