Created
July 9, 2015 12:32
-
-
Save mohsinrasool/4b998c6628bd700f1054 to your computer and use it in GitHub Desktop.
Function recursively includes all the files in the specified directory $dir and skips the ones in $skipFiles array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* It recursively includes all the files in the specified directory $dir and skips the ones in $skipFiles array | |
* Usage: | |
* include_files(dirname(__FILE__)."/models", $skipFiles); | |
* | |
* @return void | |
* @author Mohsin Rasool | |
* | |
**/ | |
function include_files($dir, $skipFiles = array('.','..')) { | |
$iterator = new DirectoryIterator($dir); | |
foreach ($iterator as $fileinfo) { | |
if(in_array($fileinfo->getFilename(),$skipFiles)) | |
continue; | |
if( $fileinfo->isFile()) { | |
require( $fileinfo->getPath().'/'.$fileinfo->getFilename() ); | |
} | |
else if($fileinfo->isDir()) { | |
include_files($fileinfo->getPath().'/'.$fileinfo->getFilename()); | |
} | |
} | |
} | |
$skipFiles = array('.','..','model.php','db.php'); | |
// include all the files from models directory | |
include_files(dirname(__FILE__)."/models", $skipFiles); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment