PHP
  Home arrow PHP arrow Page 3 - An Introduction to Building Proxy Clas...
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

An Introduction to Building Proxy Classes with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2007-01-02

    Table of Contents:
  • An Introduction to Building Proxy Classes with PHP 5
  • Developing an expandable XML processor class
  • Expanding the functionality of the ProxyXMLProcessor class
  • Defining the XMLProcessor class
  • Seeing the proxy class in action

  • 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


    An Introduction to Building Proxy Classes with PHP 5 - Expanding the functionality of the ProxyXMLProcessor class


    (Page 3 of 5 )

    As I stated in the section that you just read, my main purpose here is to extend the functionality of the already familiar proxy class, in addition to implementing its "createXMLProcessor()" method. Of course, the method will be responsible for the instantiation of XML processor objects only when its presence will be required, in this way sticking to the definition of the proxy pattern.

    Having said that, below I listed an improved version of the prior proxy class, this time including some additional methods for counting the number of nodes of an input XML string. This new incarnation of this class looks like this:

    // define 'ProxyXMLProcessor' class (proxy class for XMLProcessor) class ProxyXMLProcessor{ private $XMLProcessor=NULL; private $xmlstr; // XMLProcessor is not created here by the constructor public function __construct($xmlstr){ $this->xmlstr=$xmlstr; } // display nodes public function displayNodes($node){ // XMLProcessor object is only instantiated when any
    of its methods is called if($this->XMLProcessor==NULL){                  $this->createXMLProcessor();                 }                 return $this->XMLProcessor->displayNodes($node); } // fetch nodes as array of objects public function fetchNodesAsObjects(){ if($this->XMLProcessor==NULL){                  $this->createXMLProcessor();                 } return $this->XMLProcessor->fetchNodesAsObjects();         } // count number of nodes contained into XML string public function countNodes(){ if($this->XMLProcessor==NULL){ $this->createXMLProcessor(); }                 return $this->XMLProcessor->countNodes();       } // instantiate XMLProcessor object private function createXMLProcessor(){ $xmlObj=new XMLProcessor($this->xmlstr); $this->XMLProcessor=$xmlObj->getXMLProcessor(); } }

    Aside from implementing a new method for counting the nodes of a given XML string, the above class also exposes a private method called "createXMLProcessor." In this case, the method in question is tasked with instantiating an XML processor object when this condition is demanded. That was pretty simple, wasn't it?

    Okay, at this stage, I'm pretty certain that you understand how the previous proxy class does its business. However, I have to admit that there's still a missing piece in this puzzle that remains undefined, since you don't know how the corresponding "XMLProcessor" class looks.

    In order to address this issue and dissipate any possible doubts, in the next few lines I'm going to show you the respective signature for this XML processing class. Go ahead and read the next section.

    More PHP Articles
    More By Alejandro Gervasio


       · Over this first part of this series, you'll learn the basic concepts on how to...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT