Home arrow PHP arrow Page 3 - Working with Directory Iterators and Proxy Classes with PHP 5

Improving the functionality of the proxy class - PHP

If you’re a strong advocate of using pattern-based programming for developing your PHP applications, then this pair of comprehensive tutorials might find a place on your quick reference list. Welcome to the concluding part of the series “Building Proxy Classes with PHP 5.” In two parts, this series introduces the foundations of how to apply the proxy pattern with PHP 5, and it accompanies the corresponding theory with extensive code samples.

TABLE OF CONTENTS:
  1. Working with Directory Iterators and Proxy Classes with PHP 5
  2. Defining the initial structure of a proxy directory class
  3. Improving the functionality of the proxy class
  4. Completing the proxy pattern
  5. Developing a final example
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
January 09, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: