Gombos Lorand – Gyula
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:
files without php extension - these files will be left alone
files with *.class.php extension will be stored separately
file with only *.php extension will also be stored in a separate block
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.
We can use the class in the following cases:
if we want to include something in every class from a directory
if we have in a folder only php files and we want to use them separately from each other
if we don't want to do the includes manually, this class can do it for us (it will parse the subfolders to an infinite depth)
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.
Supposing we have a "classes" folder, and we would like to include its contents.
Structure of "classes":
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:
$includer = new Includer();
//$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();
introducing a black list, which will allow the user manually to select the files not to be included
introducing a white list, which will allow the user manually to select only the files to be included
introducing a parameter, to scan or not the subdirectories
with the help of the strategy pattern we want to create a four type link (include, include_once, require, require_once). the user can choose which one suits him better
introducing an include sorting mechanism
it should work on multiple file types, i.e. *.inc.php
checking for the object to be singleton, so it can be stored as global