PHP
  Home arrow PHP arrow Page 4 - 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 - Defining the XMLProcessor class
    ( Page 4 of 5 )

    In consonance with the concepts related to the proxy pattern that you learned before, it's necessary to define the signature of the corresponding "XMLProcessor" class. This will help you understand how a potential proxy object can access the methods that belong to different XML processors.

    This being said, below I included the signature for the pertinent "XMLProcessor" class. You'll quickly realize that it performs some useful tasks on a given XML string. Therefore, have a look at this brand new class, please:

    // define 'XMLProcessor' class class XMLProcessor{ private $sxmle; public function __construct($xmlstr){ if(!$this->sxmle=new SimpleXMLElement($xmlstr)){ throw new Exception('Error reading XLML
    string'); } } // display values of a given node public function displayNodes($node){ $nodes=''; foreach($this->sxmle as $obj){ $nodes.='Value of '.$node.' node is the
    following : '.$obj->$node.'<br />'; } return $nodes;   } // fetch all nodes as array of objects public function fetchNodesAsObjects(){ $nodes=array(); foreach($this->sxmle as $node){ $nodes[]=$node; } return $nodes; } // count number of nodes contained into XML string public function countNodes(){ $nodeCounter=0; foreach($this->sxmle as $node){ $nodeCounter++; } return $nodeCounter; } // get 'SimpleXMLElement' object public function getXMLProcessor(){ return $this; } }

    As shown above, the "XMLProcessor" class has been provided with a wealth of handy methods which can be used for counting and displaying the different nodes of a specified XML string, in addition to fetching the complete set of XML data as an array of objects. Though all the methods that I just described play an important role in the context of the XML processing class in question, I'd like you to focus your attention on the definition of the "getXMLProccessor()" method.

    As you can see, the only task assigned to the referenced method consists of simply returning to calling code an instance of the corresponding XMLProcessor" class. Logically, this condition allows a proxy class to access all the methods that belong to the respective XML processor, something that perfectly suits the requirements established by the proxy pattern.

    All right, at this level I hope that you grasped the key points on how the previous XML processing class does its thing, since its signature is indeed pretty straightforward. Thus, bearing this condition in mind, the only thing that remains undone is developing an illustrative example that will show you how the XML proxy class and its respective target object can work in tandem to process a simple XML string.

    Naturally, the example will be shown in the following section, thus to see how it will be created, please click on the link that appears below and keep reading.



     
     
    >>> 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 5 Hosted by Hostway
    Stay green...Green IT