Home arrow PHP arrow Page 3 - Using Directory Iterators and MySQL with Adapter Objects with PHP

Putting the adapter class to work - PHP

If you’re a PHP programmer who’s searching for a comprehensive tutorial on how to create adapter classes with PHP 5, them look no further. Welcome to the final installment of the series “Implementing adapter objects with PHP.” Made up of two parts, this series teaches you how to implement the adapter design pattern in PHP 5, and it accompanies the corresponding theory with educational examples.

TABLE OF CONTENTS:
  1. Using Directory Iterators and MySQL with Adapter Objects with PHP
  2. Working with directory iterators and adapters together
  3. Putting the adapter class to work
  4. Adapting MySQL result sets
By: Alejandro Gervasio
Rating: starstarstarstarstar / 6
December 13, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Naturally, I know that you want to see how the adapter class that I defined in the previous section works, therefore I prepared a concrete example that demonstrates clearly the functionality of this class.

In this case, and assuming there's a sample "default_path" directory that contains two files named "file1.txt" and "file2.txt," here's the corresponding code sample:

try{     $dirIteratorAdapter=new DirectoryIteratorAdapter(new
DirectoryIterator('default_path/'));     echo $dirIteratorAdapter->getDetailedInfo(); } catch(Exception $e){     echo $e->getMessage();     exit(); } /* displays the following: -------------------------------------------------------------------------- Last modification timestamp of current directory entry is : 1155050050 Path of current directory entry is : default_path Type of current directory entry is : dir Full path of current directory entry is :default_path/. Current directory entry is readable -------------------------------------------------------------------------- Last modification timestamp of current directory entry is : 1155061462 Path of current directory entry is : default_path Type of current directory entry is : dir Full path of current directory entry is :default_path/.. Current directory entry is readable -------------------------------------------------------------------------- Last modification timestamp of current directory entry is : 1149698631 Path of current directory entry is : default_path Type of current directory entry is : file Full path of current directory entry is :default_path/file1.txt Current directory entry is readable -------------------------------------------------------------------------- Last modification timestamp of current directory entry is : 1149698651 Path of current directory entry is : default_path Type of current directory entry is : file Full path of current directory entry is :default_path/file2.txt Current directory entry is readable */

As you can see, the prior example shows how the original "DirectoryIterator" class can be expanded without using inheritance. Also, with reference to the script listed above, you'll realize that it iterates over each directory entry and displays some useful information, such as the path of each element, type, timestamp, and so forth.

So far, with the example you saw before, I think you should be equipped with a fairly decent background on how to apply the adapter pattern with PHP 5. Nevertheless, I'd like to finish this series by teaching you another case where this pattern can be applied with minor hassles: creating an adapter that expands the capacity of a MySQL result set processing class.

Want to find out how this adapter class will be created? Jump into the following section 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: