Location: PHPKode > scripts > PHPIncluder > phpincluder/Documentation.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
	<TITLE></TITLE>
	<META NAME="GENERATOR" CONTENT="OpenOffice.org 2.4  (Win32)">
	<META NAME="AUTHOR" CONTENT="Gombos Lorand">
	<META NAME="CREATED" CONTENT="20080912;15131200">
	<META NAME="CHANGEDBY" CONTENT="Gombos Lorand">
	<META NAME="CHANGED" CONTENT="20080912;16421800">
	<STYLE TYPE="text/css">
	<!--
		@page { size: 8.5in 11in; margin: 0.79in }
		P { margin-bottom: 0.08in }
		H1 { margin-bottom: 0.08in }
		H1.western { font-family: "Arial", sans-serif; font-size: 16pt }
		H1.cjk { font-family: "Arial Unicode MS"; font-size: 16pt }
		H1.ctl { font-family: "Tahoma"; font-size: 16pt }
		H2 { margin-bottom: 0.08in }
		H2.western { font-family: "Arial", sans-serif; font-size: 14pt; font-style: italic }
		H2.cjk { font-size: 14pt; font-style: italic }
		H2.ctl { font-size: 14pt; font-style: italic }
	-->
	</STYLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<DIV TYPE=HEADER>
	<P STYLE="margin-bottom: 0in">Gombos Lorand &ndash; Gyula		<SDFIELD TYPE=DATETIME SDVAL="39703.6926388889" SDNUM="1033;1033;MM/DD/YY">09/12/08</SDFIELD></P>
	<P ALIGN=CENTER STYLE="margin-bottom: 0in"><IMG SRC="../../../Program%20Files/OpenOffice.org%202.4/share/gallery/rulers/blurulr6.gif" NAME="graphics1" ALIGN=LEFT WIDTH=640 HEIGHT=2 BORDER=0><BR CLEAR=LEFT><BR>
	</P>
	<P STYLE="margin-bottom: 0.2in"><BR>
	</P>
</DIV>
<H1 CLASS="western" STYLE="font-style: normal"><FONT COLOR="#800000"><FONT FACE="Times New Roman, serif"><FONT SIZE=6 STYLE="font-size: 25pt">PHP
Includer v1.0</FONT></FONT></FONT></H1>
<H2 CLASS="western">Objectives</H2>
<P STYLE="margin-bottom: 0in">	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.</P>
<P STYLE="margin-bottom: 0in">	This script is capable to cycle
through given catalogue, to map the inside files, including inner
folders using recursivity.</P>
<P STYLE="margin-bottom: 0in">	</P>
<P STYLE="margin-bottom: 0in">	The current version can recognize 3
types of files:</P>
<UL>
	<LI><P STYLE="margin-bottom: 0in">files without php extension -
	these files will be left alone</P>
	<LI><P STYLE="margin-bottom: 0in">files with *.class.php extension
	will be stored separately</P>
	<LI><P STYLE="margin-bottom: 0in">file with only *.php extension
	will also be stored in a separate block</P>
</UL>
<P STYLE="margin-bottom: 0in">	</P>
<P STYLE="margin-bottom: 0in">	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.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H2 CLASS="western">Usage</H2>
<P STYLE="margin-bottom: 0in">	We can use the class in the following
cases:</P>
<UL>
	<LI><P STYLE="margin-bottom: 0in">if we want to include something in
	every class from a directory</P>
	<LI><P STYLE="margin-bottom: 0in"> if we have in a folder only php
	files and we want to use them separately from each other</P>
	<LI><P STYLE="margin-bottom: 0in"> 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)</P>
</UL>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H2 CLASS="western"><IMG SRC="PHPIncluderDOC_html_3c3cb67e.gif" ALIGN=LEFT>Structure</H2>
<P STYLE="margin-bottom: 0in">	We have 2 classes. 
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">	The firs one, DirIterator, extends the
DirectoryIterator class. Its purpose is to introduce a getExtension
method. 
</P>
<P STYLE="margin-bottom: 0in">	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.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H2 CLASS="western">Example</H2>
<P STYLE="margin-bottom: 0in">	Supposing we have a &quot;classes&quot;
folder, and we would like to include its contents.</P>
<P STYLE="margin-bottom: 0in">	</P>
<P STYLE="margin-bottom: 0in">	Structure of &quot;classes&quot;:</P>
<P STYLE="margin-bottom: 0in">	classes/</P>
<P STYLE="margin-bottom: 0in">		level1/</P>
<P STYLE="margin-bottom: 0in">			level2/</P>
<P STYLE="margin-bottom: 0in">				level3</P>
<P STYLE="margin-bottom: 0in">					.</P>
<P STYLE="margin-bottom: 0in">					.</P>
<P STYLE="margin-bottom: 0in">					levleln</P>
<P STYLE="margin-bottom: 0in">	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.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><B>Index.php is as follows:</B></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT COLOR="#ff0000"><FONT FACE="Courier New, monospace"><FONT SIZE=2>&lt;?php</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><FONT COLOR="#0000ff">include_once</FONT>
<FONT COLOR="#008200">'includer.class.php'</FONT><FONT COLOR="#000000">;</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><FONT COLOR="#660000">$includer</FONT>
<FONT COLOR="#000000">=</FONT> <FONT COLOR="#0000ff">new</FONT>
<FONT COLOR="#000000">Includer();</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><FONT COLOR="#660000">$includer</FONT><FONT COLOR="#000000">-&gt;Import(</FONT><FONT COLOR="#008200">'classes'</FONT><FONT COLOR="#000000">);</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT COLOR="#808080"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//$a-&gt;Test();
			//outputs the contents of the blocks</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT COLOR="#808080"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//$a-&gt;ImportClasses();
		//if we use only *.clss.php files</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT COLOR="#808080"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//$b
= $a-&gt;ImportPhpFiles(); 	//if we use only *.php files</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><FONT COLOR="#660000">$includer</FONT><FONT COLOR="#000000">-&gt;ImportAll();</FONT>
	<FONT COLOR="#808080">//if we use every file</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><FONT COLOR="#660000">$class1</FONT>
<FONT COLOR="#000000">=</FONT> <FONT COLOR="#0000ff">new</FONT>
<FONT COLOR="#000000">Sample1();</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><FONT COLOR="#660000">$class2</FONT>
<FONT COLOR="#000000">=</FONT> <FONT COLOR="#0000ff">new</FONT>
<FONT COLOR="#000000">Sample2();</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><FONT COLOR="#660000">$class3</FONT>
<FONT COLOR="#000000">=</FONT> <FONT COLOR="#0000ff">new</FONT>
<FONT COLOR="#000000">Level1();</FONT></FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT COLOR="#ff0000"><FONT FACE="Courier New, monospace"><FONT SIZE=2>?&gt;</FONT></FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H2 CLASS="western">Future developments</H2>
<UL>
	<LI><P STYLE="margin-bottom: 0in">introducing a black list, which
	will allow the user manually to select the files not to be included</P>
	<LI><P STYLE="margin-bottom: 0in">introducing a white list, which
	will allow the user manually to select only the files to be included</P>
	<LI><P STYLE="margin-bottom: 0in">introducing a parameter, to scan
	or not the subdirectories</P>
	<LI><P STYLE="margin-bottom: 0in">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</P>
	<LI><P STYLE="margin-bottom: 0in">introducing an include sorting
	mechanism</P>
	<LI><P STYLE="margin-bottom: 0in">it should work on multiple file
	types, i.e. *.inc.php</P>
	<LI><P STYLE="margin-bottom: 0in">checking for the object to be
	singleton, so it can be stored as global</P>
</UL>
<P STYLE="margin-bottom: 0in"><BR>
</P>
</BODY>
</HTML>
Return current item: PHPIncluder