PHP
  Home arrow PHP arrow Page 5 - Expanding an Error Logger with the Chain of Responsibility Pattern
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Expanding an Error Logger with the Chain of Responsibility Pattern
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2006-11-13


    Table of Contents:
  • Expanding an Error Logger with the Chain of Responsibility Pattern
  • The error logging system's responsibility chain
  • Expanding the basic error logging system
  • Logging errors when something goes wrong
  • The error logging system in action

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Expanding an Error Logger with the Chain of Responsibility Pattern - The error logging system in action
    ( Page 5 of 5 )

    If you're like me, then you'll think that the best way of understanding how the  error logging system works is by developing a comprehensive example which uses all the classes in conjunction.

    Therefore, below you'll see a simple script I coded that shows the respective behaviors followed by all the classes defined over the previous sections, whether or not a concrete error logger has been set. Please look at this handy group of examples:

    try{
        // instantiate 'ErrorLogger' object
        $errorLogger=new ErrorLogger();
        // validate email without providing an error logger
        $errorLogger->getErrorLogger();
        /* 
        displays the following: 
        No error logger has been set!
        */
    }
    catch(Exception $e){
        echo $e->getMessage();
        exit();
    }
    try{
        // instantiate 'ErrorLogger' object
        $errorLogger=new ErrorLogger();
        // instantiate 'FileErrorLogger'
        $fileErrorLogger=new FileErrorLogger($errorLogger);
        // instantiate 'EmailValidator' object
        //$emailValidator=new EmailValidator('username@domain.com',$fileErrorLogger);
        //$emailValidator->validate();
        /*
        displays the following:
        No error logger has been set!
        */
    }
    catch(Exception $e){
        echo $e->getMessage();
        exit();
    }
    try{
        // instantiate 'ErrorLogger' object
        $errorLogger=new ErrorLogger();
        // provide an error logger
        $fileErrorLogger=new FileErrorLogger($errorLogger);
        $fileErrorLogger->setErrorLogger('File Error Logger');
        $emailValidator=new EmailValidator('username@domain.com',$fileErrorLogger);
        $emailValidator->validate();
    }
    catch(Exception $e){
        echo $e->getMessage();
        exit();
    }

    As shown above, the first two examples demonstrate clearly how the chain of responsibility is moved up toward the base "ErrorLogger" class when an appropriate error logger isn't provided to the scripts. This condition is reflected by the outputs generated by each script, since they complain loudly about this condition by displaying the following message:

    No error logger has been set!

    Finally, the last example illustrates a concrete case where a "FileErrorLogger" object is injected straight into the respective "EmailValidator" class. As you'll realize, this fact obviously allows the correct implementation of its "validate()" method. As usual, I suggest you to try modifying the previous examples and see what happens in each case.

    Final thoughts

    I'm finished now. In this three-part series, I introduced you to the basics of how to implement the chain of responsibility pattern with PHP 5. I hope that all the examples that were shown in this set of articles will help you start applying this schema in your own PHP applications. See you in the next PHP tutorial! 



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek