PHP
  Home arrow PHP arrow Page 3 - 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 - Improving the functionality of the proxy class
    ( Page 3 of 5 )

    Since the initial functionality provided by the prior "ProxyDirectoryProcessor" class is pretty limited, it would be desirable to add to it some additional methods. These will help with performing some useful tasks, such as retrieving the access timestamps that correspond to the different directory entries, as well as fetching some information concerning the respective index nodes.

    Aside from all the operations that I mentioned before, it's necessary to define another specific method. This method will be responsible for creating a directory processor object when this process will be required by the proxy class in question.

    Therefore, keeping in mind all the functionality that I want to give to the proxy class, below I listed its improved signature. Have a look at it, please:

    // 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(); } // get timestamps of directory entries public function getTimeStamps(){ if($this->dirProcessor==NULL){ $this->createDirectoryProcessor(); } return $this->dirProcessor->getTimeStamps(); } // get last-access timestamps of directory entries public function getLastTimeStamps(){ if($this->dirProcessor==NULL){ $this->createDirectoryProcessor(); } return $this->dirProcessor->getLastTimeStamps(); } // get last access timestamps of inodes public function getInodeLastTimeStamps(){ if($this->dirProcessor==NULL){ $this->createDirectoryProcessor(); } return $this->dirProcessor->getInodeLastTimeStamps(); } // instantiate dirProcessor object private function createDirectoryProcessor(){ $dirObj=new DirectoryProcessor($this->dirPath); $this->dirProcessor=$dirObj->getDirectoryProcessor(); } }

    As you can see above, now the proxy class is capable of performing all the additional tasks that I discussed a few lines before, since I included some extra methods. Most of them deal with different types of timestamps. Besides, you'll realize that there's a new method called the "createDirectoryProcessor()" object, which is tasked with returning to calling code a directory processor object. That was easy, wasn't it?

    All right, at this stage, the previously defined proxy class possess some decent functionality. This functionality is logically provided by a directory processor object, according to the definition for the proxy pattern. So what's the next step? Naturally, the next thing that I'm going to do is show you the signature for the pertinent directory processor class, in this way getting the pattern's schema completed.

    To learn how this new directory processor class will be created, please click on the link shown below and keep reading.



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

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - 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





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