PHP
  Home arrow PHP arrow Page 5 - 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 - Seeing the proxy class in action


    (Page 5 of 5 )

    In accordance with the concepts that I deployed in the prior section, the simplest way to understand how the corresponding "ProxyXMLProcessor" class works to access all the methods of a potential XML processor object rests on setting up a comprehensive example. In this example, a simple XML string will be processed by using the proxy pattern.

    For this specific case, say you have the following sample XML string in a file called "xmlstr.php:"

    <?php $xmlstr=<<<XML <?xml version="1.0" encoding="iso-8859-1"?> <users> <user> <name>John Doe</name> <location>Location 1</location> <email>john@domain.com</email> </user> <user> <name>Mary Shelley</name> <location>Location 2</location> <email>mary@domain.com</email> </user> <user> <name>Peter Parker</name> <location>Location 3</location> <email>peter@domain.com</email> </user> <user> <name>Susan Norton</name> <location>Location 4</location> <email>susan@domain.com</email> </user> <user> <name>Steve Powell</name> <location>Location 5</location> <email>steve@domain.com</email> </user> </users> XML; ?>

    Now, after listing the above XML string, it's possible to use the previous XML proxy class in the following way:

    try{ // include XML string require_once 'xmlstr.php'; // instantiate 'ProxyXMLProcessor' object $pxmlproc=new ProxyXMLProcessor($xmlstr); // display number of 'email' nodes contained into XML string echo $pxmlproc->displayNodes('email'); /* displays the following:            Value of email node is the following : john@domain.com Value of email node is the following : mary@domain.com Value of email node is the following : peter@domain.com Value of email node is the following : susan@domain.com Value of email node is the following : steve@domain.com */          // fetch nodes as array of objects echo $pxmlproc->fetchNodesAsObjects(); /* displays the following: array */ // count number of nodes contained into XML string             echo $pxmlproc->countNodes(); /*           displays the following: 5 */ } catch(Exception $e){ echo $e->getMessage(); exit(); }

    As you can see, the previous example shows clearly how the corresponding "XMLProxyProcessor" can be used to count, display and fetch all the nodes contained in the XML string that you saw before, by using all the methods exposed by an XML processor object.

    After studying the above example, you'll agree with me that building proxy classes with PHP 5 is indeed a no-brainer process, right?

    Wrapping up

    We've come to the end of this first part of the series. Aside from introducing the core concepts for how to implement the proxy pattern with PHP 5, I provided you with some examples that may help you understand more easily how this pattern works.

    In the final article of this series, I'll show you how to use this handy pattern to construct a proxy object for the "DirectoryIterator" class that comes bundled with PHP 5. So, stay tuned until the next part!  


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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