PHP
  Home arrow PHP arrow Page 2 - Developing a Recursive Loading Class for Loader Applications in 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

Developing a Recursive Loading Class for Loader Applications in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2009-06-18


    Table of Contents:
  • Developing a Recursive Loading Class for Loader Applications in PHP
  • Review: building a basic file loading class with PHP 5
  • Defining a class with recursive file searching capabilities
  • Defining the recursive load() method

  • 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


    Developing a Recursive Loading Class for Loader Applications in PHP - Review: building a basic file loading class with PHP 5
    ( Page 2 of 4 )

    At this point, I'm sure you want to learn how to build a file loading class with recursive searching capabilities. However, before we do that, it would be helpful to quickly recall the definition and usage of the “Loader” class developed in the preceding part of the series, so you can compare it with the one that I plan to create. 

    Below I listed the full source code of the previous loader class, accompanied by a short example that shows how to work with it. First, here’s the signature of the “Loader” class:

     

    // define the loader class (the 'load()' method is declared static)

    class Loader

    {

    // constructor (not implemented)

    public function __construct(){}

     

    // load specified file

    public static function load($filepath)

    {

    if (!file_exists($filepath))

    {

    throw new Exception('The specified file cannot be found!');

    }

    require_once($filepath);

    }

    }

     

    Next, we'll reintroduce the two sample files that will be included by the class. Here they are:

     

    ('sample_file1.php')

     

    <?php

    echo ' This file has been loaded with the Loader class.' . '<br />';

    ?>

     

     

    ('sample_file2.php')

     

    <?php

    echo 'This file has been loaded at the following time: ' . date('H:i:s');

    ?>

     

    And finally, here’s a small code snippet that shows the “Loader” class in action, using its static “load()” method:

     

    <?php

    try

    {

    // call 'load()' method statically and load specified files

    Loader::load('sample_file1.php');

    Loader::load('sample_file2.php');

     

    /* displays the following

    This file has been loaded with the Loader class.

    This file has been loaded at the following time 11:37:09

    */

    }

    catch (Exception $e)

    {

    echo $e->getMessage();

    exit();

    }

    ?>

     

    From the code sample shown above, it’s clear to see how simple the logic is that is implemented by the pertinent “Loader()” class. All it does is include a specified file via its static “load()” method, which is merely a proxy for the native “require_once()” PHP function. 

    In general terms, due to its basic structure, this class could be considered a file loader helper, rather than a core library of a fictional framework. Of course, as you might have imagined, it’s perfectly feasible to use the skeleton of the class and construct a more advanced and complex version of it, capable of searching recursively targeted files and including them inside a PHP application. 

    That’s exactly what I’m going to do in the course of the following section: build a recursive file loader class. So, if you want to learn the full details of this process, click on the link that appears below and keep reading.



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

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - 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...





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