PHP
  Home arrow PHP arrow Page 3 - Building a Data Validation System with...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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? 
PHP

Building a Data Validation System with the Prototype Pattern with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · This last article of the series goes through the development of a data validation...
       · First I want to say that I enjoy reading your articles. They are clearly written...
       · Firstly, I’d like to say I’m glad you find my PHP articles useful, so I thank you...
     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway