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

       

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek