PHP
  Home arrow PHP arrow Page 4 - An Introduction to Building Proxy Clas...
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 - 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


       · 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 4 hosted by Hostway
    Stay green...Green IT