Skip to content

Commit

Permalink
完善类库和ORM的自动加载
Browse files Browse the repository at this point in the history
  • Loading branch information
breath-co2 committed Sep 12, 2013
1 parent d491934 commit 1879b87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
34 changes: 19 additions & 15 deletions core/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,48 +704,47 @@ public static function auto_load($class_name)
else if ($class_name_array[0]=='ex')
{
# 扩展别名
$is_alias = true;
$is_alias = true;
$new_class_name = $class_name_array[1];
}
else if (preg_match('#^library_((?:[a-z0-9]+)_(?:[a-z0-9]+))_([a-z0-9_]+)$#', $class_name, $m))
{
$ns = 'library';
$ns_name = str_replace('_', DS, $m[1]);
$ns = 'library';
$ns_name = str_replace('_', DS, $m[1]);
$new_class_name = $m[2];
}
else if (preg_match('#^module_(.*)$#', $class_name, $m))
{
# Module 组件
$ns = 'module';
# 组件
$ns = 'module';
list($ns_name) = explode('_', $m[1], 2);
$new_class_name = $m[1];
}
else if (preg_match('#^driver_([a-z0-9]+)_driver_([a-z0-9_]+)$#', $class_name, $m))
{
# 驱动
$ns = 'driver';
$ns_name = $m[1];
$ns = 'driver';
$ns_name = $m[1];
$new_class_name = $m[2];
}
else
{
$ns = '';
$ns = '';
$new_class_name = $class_name;
}

# 获取类的前缀
$prefix = '';
$new_class_arr = explode('_', $new_class_name, 2);
$new_class_arr = explode('_', $new_class_name);

if (2===count($new_class_arr))
if (count($new_class_arr)>=2)
{
$prefix = $new_class_arr[0];
$prefix = array_shift($new_class_arr);
}

if ($prefix && isset(self::$dir_setting[$prefix]))
{
$dir_setting = self::$dir_setting[$prefix];
$class_file_name = $new_class_arr[1];
$dir_setting = self::$dir_setting[$prefix];

if ($prefix=='controller')
{
Expand All @@ -766,12 +765,17 @@ public static function auto_load($class_name)
$dir_setting[0] .= '-rest';
}
}
else if ($prefix=='orm')
{
array_pop($new_class_arr);
}

$class_file_name = implode(DS, $new_class_arr);
}
else
{
$dir_setting = self::$dir_setting['class'];
$class_file_name = $new_class_name;
$class_file_name = str_replace('_', DS, $new_class_name);
}

if ($ns)
Expand Down Expand Up @@ -801,7 +805,7 @@ public static function auto_load($class_name)
break;
}

$file .= str_replace('_', DS, $class_file_name) . $dir_setting[1] . EXT;
$file .= $class_file_name . $dir_setting[1] . EXT;

if (is_file($file))
{
Expand Down
15 changes: 12 additions & 3 deletions core/classes/core.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,17 @@ protected static function find_controller($uri)
$found_path = array();
foreach ($include_path as $ns => $ipath)
{
foreach ($ipath as $path)
if($ipath)foreach ($ipath as $lib_ns => $path)
{
if ($ns==='library')
{
$tmp_ns = 'library_' . str_replace('.', '_', $lib_ns);
}
else
{
$tmp_ns = $ns;
}

$tmp_str = $real_path = $real_class = '';
$tmp_path = $path . $controller_dir . DS;
$ids = array();
Expand Down Expand Up @@ -837,7 +846,7 @@ protected static function find_controller($uri)
{
$found_path[$tmp_str][] = array
(
$ns,
$tmp_ns,
$tmpdir,
ltrim($real_class, '_'),
$ids,
Expand All @@ -854,7 +863,7 @@ protected static function find_controller($uri)
{
$found_path[''][] = array
(
$ns,
$tmp_ns,
$tmp_path,
'',
array(),
Expand Down

0 comments on commit 1879b87

Please sign in to comment.