Skip to content

Instantly share code, notes, and snippets.

@geofmureithi-zz
Forked from pwenzel/require_all_helper.php
Created April 20, 2016 16:27
Show Gist options
  • Save geofmureithi-zz/eb737134fa2ecc831c9da30b05bbc320 to your computer and use it in GitHub Desktop.
Save geofmureithi-zz/eb737134fa2ecc831c9da30b05bbc320 to your computer and use it in GitHub Desktop.
Recursively include all PHP files
<?php
/**
* Scan the api path, recursively including all PHP files
*
* @param string $dir
* @param int $depth (optional)
*/
protected function _require_all($dir, $depth=0) {
if ($depth > $this->max_scan_depth) {
return;
}
// require all php files
$scan = glob("$dir/*");
foreach ($scan as $path) {
if (preg_match('/\.php$/', $path)) {
require_once $path;
}
elseif (is_dir($path)) {
$this->_require_all($path, $depth+1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment