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

Developing a final example - 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

As I promised before, below I developed an illustrative example that shows how to obtain useful information about a sample "defaultPath" directory, which also contains two text files called "file1.txt" and "file2.txt" respectively. For this specific example, I listed sequentially the different values outputted when a particular method is called, so you can see more clearly how the proxy class does its business.

Here is the example in question:

try{ // instantiate 'ProxyDirectoryProcessor' object $pDirProc=new ProxyDirectoryProcessor(); // display path of selected directory echo $pDirProc->getPath(); /* displays the following: defaultPath */ // display size of directory entries echo $pDirProc->getSize(); /* displays the following: Size for directory entries are as following: Size for current element is :0 Size for current element is :0 Size for current element is :29 Size for current element is :29 */ // display names of directory entries echo $pDirProc->getFileNames(); /* displays the following: Name for directory entries are as following: Name of current file is : file1.txt Name of current file is : file2.txt */ // display timestamps of directory entries echo $pDirProc->getTimeStamps(); /* displays the following: Timestamps for directory entries are as following: Timestamp of current file is : 1160523911 Timestamp of current file is : 1160523922 */ // display last access timestamps of directory entries echo $pDirProc->getLastTimeStamps(); /* displays the following: Last access timestamps for directory entries are as following: Last access timestamp of current file is : 1160523911 Last access timestamp of current file is : 1160523922 */ // display inode timestamps of directory entries         echo $pDirProc->getInodeLastTimeStamps();         /* displays the following: Last inode modification timestamp for directory entries are
as following: Last inode modification timestamp of current file is : 1160523911 Last inode modification timestamp of current file is : 1160523922 */ } catch(Exception $e){ echo $e->getMessage(); exit(); }

After studying the above example, hopefully you'll have a better background on how the proxy pattern works. As homework, try defining more methods for the directory processor, and for the proxy class as well. Fun is already guaranteed!

Final thoughts

In this two-part series, I introduced the key points concerning the implementation of the proxy pattern in PHP 5. As you hopefully learned, this pattern can be used when you want to avoid an unnecessary instantiation of a particular object, something that eventually can improve the overall performance of your application.

As usual, see you in the next PHP tutorial!



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap

Dev Shed Tutorial Topics: