PHP
  Home arrow PHP arrow Page 2 - Using Directory Iterators and MySQL with Adapter Objects with PHP
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

Using Directory Iterators and MySQL with Adapter Objects with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2006-12-13


    Table of Contents:
  • Using Directory Iterators and MySQL with Adapter Objects with PHP
  • Working with directory iterators and adapters together
  • Putting the adapter class to work
  • Adapting MySQL result sets

  • 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


    Using Directory Iterators and MySQL with Adapter Objects with PHP - Working with directory iterators and adapters together
    ( Page 2 of 4 )

    The first example that I plan to develop in this article is focused on creating an adapter class which will eventually expand the functionality of the popular "DirectoryIterator" class included with the SPL package. Additionally, even when this approach may not be the best one (inheritance is preferred for this specific case), it will allow me to demonstrate how to use the adapter pattern in a more useful situation.

    Having clarified the above issue, take a look at the following code snippet, which defines the pair of classes that comprise the adapter entity discussed earlier:

    //define abstract 'AbstractDirectoryIteratorAdapter' class
    
    abstract class AbstractDirectoryIteratorAdapter{
     
        private $dirIterator;
    
        abstract public function getDetailedInfo();
    
    }
    
    //define concrete 'DirectoryIteratorAdapter' class
    
    class DirectoryIteratorAdapter extends AbstractDirectoryIteratorAdapter{
    
       public function__construct(DirectoryIterator $dirIterator){
           
    	$this->dirIterator=$dirIterator;
    
        }
    
        public function getDetailedInfo(){
    
            $info='';
       
    	foreach($this->dirIterator as $dirEntry){
    
                $info.=str_repeat('-',80).'<br/>';
    
                $info.='Last modification timestamp of current directory 
    entry is :'.$dirEntry->getMTime().'<br />';             $info.='Path of current directory entry is :
    '.$dirEntry->getPath().'<br />';             $info.='Type of current directory  entry is :
    '.$dirEntry->getType().'<br />';             $info.='Full path of current directory entry is :
    '.$dirEntry->getPathName().'<br/>';             $info.=$dirEntry->isReadable()?'Current directory entry is
    readable<br />':'Current directory entry is not readable<br />';         }         return $info;              } }

    If you take some time and examine the above example, you'll realize that there are some interesting aspects worthy of highlighting here. First, notice how the constructor that corresponds to this new "DirectoryIteratorAdapter" class takes up an object of type "DirectoryIterator," which is assigned opportunely as a class property.

    As you can see, the reason for doing this is really obvious. Since I'm not using inheritance in this case, the simplest way to expand the functionality of a specific class is by simply injecting the class in question straight into its adapter. That was simple, wasn't it?

    Second, the previous adapter class also exposes the "getDetailedInfo()" method, which uses three predefined methods that come with "DirectoryIterator" to expand its original functionality and provide more specific information about a given directory and its corresponding entries.

    In addition, I'd like to note that I used the conventional approach for concatenating strings inside this referenced method, but you can easily change this and utilize the "heredoc" syntax, which is slightly more understandable.

    At this stage, I'm pretty certain that you grasped the technique that I applied here for creating an adapter class, aimed at extending the functionality of the familiar "DirectoryIterator." However, there is still more material to learn, since I want to show you how this adapter class works with a concrete example.

    Sounds really intriguing, right? Then, don't waste any more time; read the following section.



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