PHP
  Home arrow PHP arrow Page 2 - Working with Directory Iterators and 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

Working with Directory Iterators and Proxy Classes with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    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
     

       

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