PHP
  Home arrow PHP arrow Page 5 - 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? 
Google.com  
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 - 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!  



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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 ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek