本文整理汇总了PHP中DataMapper::recursive_require_once方法的典型用法代码示例。如果您正苦于以下问题:PHP DataMapper::recursive_require_once方法的具体用法?PHP DataMapper::recursive_require_once怎么用?PHP DataMapper::recursive_require_once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataMapper
的用法示例。
在下文中一共展示了DataMapper::recursive_require_once方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recursive_require_once
/**
* Recursive Require Once
*
* Recursively searches the path for the class, require_once if found.
*
* @param string $class Name of class to look for
* @param string $path Current path to search
*/
protected static function recursive_require_once($class, $path)
{
$found = FALSE;
if (is_dir($path)) {
$handle = opendir($path);
if ($handle) {
while (FALSE !== ($dir = readdir($handle))) {
// If dir does not contain a dot
if (strpos($dir, '.') === FALSE) {
// Prepare recursive path
$recursive_path = $path . '/' . $dir;
// Prepare file
$file = $recursive_path . '/' . $class . EXT;
// Check if file exists, require_once if it does
if (file_exists($file)) {
require_once $file;
$found = TRUE;
break;
} else {
if (is_dir($recursive_path)) {
// Do a recursive search of the path for the class
DataMapper::recursive_require_once($class, $recursive_path);
}
}
}
}
closedir($handle);
}
}
return $found;
}
示例2: autoload
static function autoload($class)
{
// Don't attempt to autoload CI_ or MY_ prefixed classes
if (in_array(substr($class, 0, 3), array('CI_', 'MY_'))) {
return;
}
// Prepare class
$class = strtolower($class);
// Prepare path
$path = APPPATH . 'modules';
if (is_dir($path)) {
if ($handle = opendir($path)) {
while (FALSE !== ($dir = readdir($handle))) {
// If dir does not contain a dot
if (strpos($dir, '.') === FALSE) {
$modules[] = $dir;
}
}
}
}
foreach ($modules as $module) {
// Prepare path
$path = APPPATH . 'modules/' . $module . '/models';
// Verify if there is a models folder on Module folder
if (is_dir($path)) {
// Prepare file
$file = $path . '/' . $class . EXT;
// Check if file exists, require_once if it does
if (file_exists($file)) {
require_once $file;
} else {
// Do a recursive search of the path for the class
DataMapper::recursive_require_once($class, $path);
}
}
}
}