本文整理匯總了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);
}
}
}
}