note 42896 deleted from function.include by tomsommer
| From: | tomsommer@php.net | Date: | Tue, 06 Jul 2004 11:41:30 +0000 |
| Subject: | note 42896 deleted from function.include by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72755@lists.php.net to get a copy of this message | ||
Note Submitter: cbrumelle@xaia.ca
----
Over the years Ive built up a large library of custom classes and I hate having to
require_once huge numbers of them in a config file. I wrote this simple little function that
imports all the files in a directory.
It helps me
maybe it can help someone else.
<?php
/*----------------------------------------
* Import
*------------------------------------------
* Similiar to Java's import statement...
*
* This function calls 'require_once()' for all files that end
* with '.php' (by default), or end with the string passed in
* the optional second parameter '$ext', in the directory specified
* in '$path'.
*
* Example:
*
* import('lib/Auth', '.inc'); //includes all files in the ./lib/Auth dir that
end with '.inc'
* import('lib/Cart); //includes all files in the ./lib/Cart dir that end with '.php'
*/
function import($path, $ext = '.php'){
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (substr($file, -(strlen($ext))) == $ext)
require_once($path.'/'.$file);
}
}
closedir($handle);
}
?>
Colin Brumelle