PHP
  Home arrow PHP arrow Page 3 - Building a Data Validation System with the Prototype Pattern with PHP 5
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

Building a Data Validation System with the Prototype Pattern with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2007-05-22


    Table of Contents:
  • Building a Data Validation System with the Prototype Pattern with PHP 5
  • Building a simple data validation system
  • Creating a few additional classes
  • Creating an example

  • 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


    Building a Data Validation System with the Prototype Pattern with PHP 5 - Creating a few additional classes
    ( Page 3 of 4 )

    As you'll certainly recall from the previous section, my intention here is to extend the functionality of this simple data validation application to make it capable of checking some additional incoming data, like numbers and email addresses.

    Logically, these brand new classes will also declare the magic "__clone()" method that you saw earlier, so they can clone objects that might be needed by an application.

    Now that I've clarified how these data checking classes are going to work, please take a minute and examine their respective signatures, which look like this:

    // define concrete 'NumbericValidatorPrototype' class
    class NumbericValidatorPrototype extends DataValidatorPrototype{
       public function validateData($inputData){
         if(!$inputData||!is_numeric($inputData)){
           return false;
         }
         return true;
       }
       public function __clone(){}
    }

    // define concrete 'EmailValidatorPrototype' class
    class EmailValidatorPrototype extends DataValidatorPrototype{
       public function validateData($inputData){
         if(!$inputData||!preg_match("/.+@.+\..+./",$inputData)||!
    checkdnsrr(array_pop(explode("@",$inputData)),"MX")){
           return false;
         }
         return true;
       }
       public function __clone(){}         
    }

    As you can see, the prototype classes listed above implement the same business logic present in their predecessors concerning the declaration of the "__clone()" method. The definition of the method has been done deliberately, providing each validation class with the capacity to clone objects across a given application.

    So far, so good. At this point hopefully you've grasped the functionality of each of the prototype classes defined previously. However, I'm pretty certain that you're asking yourself…how can the prototype pattern be linked with the classes in question?

    Well, to answer that smart question, in the section to come I'm going to develop a short script. It will show how multiple instances of the data checking classes that you have just learned can be put to work in conjunction.

    Hopefully, after you see the example, you'll have a more polished concept of how the prototype pattern functions.

    To see how this practical example will be developed, please jump ahead and read the next few lines. I'll be there, waiting for you.



     
     
    >>> 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek