PHP
  Home arrow PHP arrow Page 2 - Working with Directory Iterators and P...
Dev Shed Forums 
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

Working with Directory Iterators and Proxy Classes with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-01-09

    Table of Contents:
  • Working with Directory Iterators and Proxy Classes with PHP 5
  • Defining the initial structure of a proxy directory class
  • Improving the functionality of the proxy class
  • Completing the proxy pattern
  • Developing a final example

  • 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


    Working with Directory Iterators and Proxy Classes with PHP 5 - Defining the initial structure of a proxy directory class


    (Page 2 of 5 )

    In consonance with the concepts that I explained in the introduction, I'm going to demonstrate how to build a generic proxy class that can be easily coupled with a directory iterator. The result of this integration will allow you develop a simple application that collects information about a selected directory via a proxy object.

    Since the challenge is really appealing, let me commence by showing you the initial signature for this new proxy class. Its source code is as follows:

    // define 'DirectoryProcessor' class class ProxyDirectoryProcessor{ private $dirPath; private $dirProcessor=NULL; public function __construct($dirPath='defaultPath'){ if(!is_dir($dirPath)){ throw new Exception('Invalid input directory'); } $this->dirPath=$dirPath; } // get directory path public function getPath(){ if($this->dirProcessor==NULL){ $this->createDirectoryProcessor(); } return $this->dirProcessor->getPath(); } //get size of directory entries public function getSize(){ if($this->dirProcessor==NULL){ $this->createDirectoryProcessor(); } return $this->dirProcessor->getSize(); } //get names of directory entries public function getFileNames(){ if($this->dirProcessor==NULL){ $this->createDirectoryProcessor(); } return $this->dirProcessor->getFileNames(); } }

    If you're familiar with how the proxy pattern works, then you'll find the above class extremely easy to grasp. As you can see, the previous "ProxyDirectoryProcessor" class has some neat methods for retrieving some useful information about the entries included into a selected directory, such as their size, names and path respectively.

    Also, you should noticed how the proxy class obtains all this data by using the group of methods provided by a directory processor object, which for the moment remains undefined. In addition, I'd like to stress one point that deserves special attention here: note how this directory processor isn't instantiated by the corresponding constructor; instead, the object in question is only created when its functionality is required. Pretty neat, right?

    Okay, I think that the previous proxy class now gives you a clear idea of how it works, as well as how it can be easily coupled with a directory iterator. However, the functionality offered by this class is rather limited, so let me add some extra methods to it before I proceed to define the respective director processor class that you saw before.

    Do you want to see how this will be done? Please click on the link below and keep reading. 

    More PHP Articles
    More By Alejandro Gervasio


       · Over this final installment of the series, you'll learn how to create proxy objects,...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - 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
    - 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
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT