Gombos Lorand – Gyula 09/12/08




PHP Includer v1.0

Objectives

I suppose, many of you encountered the situation where the number of used classes reached 10 or even more. We can store this in a classes folder. When we want to use them, it might not be the best solution to include them.

This script is capable to cycle through given catalogue, to map the inside files, including inner folders using recursivity.

The current version can recognize 3 types of files:

One field in the blocks is depth. It shows how deep the file is in the file system. This does not have any purpose in the v1.0 version.


Usage

We can use the class in the following cases:


Structure

We have 2 classes.


The firs one, DirIterator, extends the DirectoryIterator class. Its purpose is to introduce a getExtension method.

The second class is the Includer. The logic is done by the Import method, which runs through folders using recursivity, so it can map all the subfolders.


Example

Supposing we have a "classes" folder, and we would like to include its contents.

Structure of "classes":

classes/

level1/

level2/

level3

.

.

levleln

We have an includer.class.php file which contains the Icluder class, and we have an index.php where we want to include the contents of classes.


Index.php is as follows:


<?php

include_once 'includer.class.php';

$includer = new Includer();

$includer->Import('classes');

//$a->Test(); //outputs the contents of the blocks

//$a->ImportClasses(); //if we use only *.clss.php files

//$b = $a->ImportPhpFiles(); //if we use only *.php files

$includer->ImportAll(); //if we use every file


$class1 = new Sample1();

$class2 = new Sample2();

$class3 = new Level1();

?>


Future developments