PHP
  Home arrow PHP arrow Page 4 - 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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
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

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    Working with Directory Iterators and Proxy Classes with PHP 5 - Completing the proxy pattern


    (Page 4 of 5 )

    As I stated in the section that you just read, in order to complete the programmatic model imposed by the proxy pattern, I need to define the signature that corresponds to the "DirectoryProcessor" class. As you just learned, this class is used by the aforementioned proxy.

    Since my intention here is to demonstrate how a proxy class can be coupled with a directory iterator, the directory process that I plan to build will consist of a simple wrapper for the "DirectoryIterator" class that comes with PHP 5. It's just as simple as it sounds.

    Having said that, here is the definition for this brand new class:

    // define 'DirectoryProcessor' class class DirectoryProcessor{ private $dirProcessor; public function __construct($dirPath){ if(!$this->dirProcessor=new
    DirectoryIterator($dirPath)){ throw new Exception('Error instantiating
    directory processor object'); } } // get path of selected directory public function getPath(){ return $this->dirProcessor->getPath(); } // get size of directory entries public function getSize(){ $output='Sizes for directory entries are as
    following:<br />'; foreach($this->dirProcessor as $dirElement){ $output.='Size for current element
    is :'.$dirElement->getSize().'<br />'; } return $output; } // get names of directory entries public function getFileNames(){ $output='Names for directory entries are as
    following:<br />'; foreach($this->dirProcessor as $dirElement){ if($dirElement->isFile()){ $output.='Name of current file
    is : '.$dirElement->getFileName().'<br />'; } } return $output; } // get timestamps of directory entries public function getTimeStamps(){ $output='Timestamps for directory entries are as
    following:<br />'; foreach($this->dirProcessor as $dirElement){ if($dirElement->isFile()){ $output.='Timestamp of current file
    is : '.$dirElement->getMTime().'<br />'; }                  }                  return $output; } // get last access timestamps of directory entries public function getLastTimeStamps(){ $output='Last access timestamps for directory entries
    are as following:<br />'; foreach($this->dirProcessor as $dirElement){ if($dirElement->isFile()){   $output.='Last access timestamp of current
    file is : '.$dirElement->getATime().'<br />';                          }                         }                         return $output;             }             // get last access timestamps of inodes             public function getInodeLastTimeStamps(){ $output='Last inode modification timestamp for
    directory entries are as following:<br />'; foreach($this->dirProcessor as $dirElement){                 if($dirElement->isFile()){                 $output.='Last inode modification timestamp of current
    file is :'.$dirElement->getCTime().'<br />';                  }                  } return $output; }             // get directory processor object             public function getDirectoryProcessor(){ return $this; } }

    Now, definitely things are getting really interesting! As you can see, the above "DirectoryProcessor" class behaves like a simple wrapping layer for the popular "DirectoryIterator" class that you've used many times with your PHP 5-based applications. In this case in particular, all the functionality provided by the original proxy class is implemented concretely by the corresponding iterator.

    Now that you know how the previous directory processor class looks, it's time to jump forward and tackle the final section of the article, where I'll be demonstrating how the pair of neat classes that I created can be integrated in a single example.

    Provided that you're interested in learning how these classes fit each other, go ahead and read the next few lines. I'll be there, waiting for you.

    More PHP Articles
    More By Alejandro Gervasio


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

       

    PHP ARTICLES

    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...




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