PHP
  Home arrow PHP arrow Page 3 - An Introduction to Building Proxy Classes 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? 
PHP

An Introduction to Building Proxy Classes with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    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:
      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


    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
     

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT