-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
1521 lines (1313 loc) · 41.6 KB
/
bootstrap.php
File metadata and controls
1521 lines (1313 loc) · 41.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* 当前系统启动时间
*
* @var int
*/
define('START_TIME', microtime(1));
/**
* 启动内存
*
* @var int 启动所用内存
*/
define('START_MEMORY', memory_get_usage());
/**
* 定义MyQEE大版本
*
* @var string
*/
define('MYQEE_VERSION', 'v3');
/**
* PHP文件后缀
*
* @var string
*/
define('EXT', '.php');
/**
* 系统当前时间
*
* @var int
*/
define('TIME', time());
/**
* 目录分隔符简写
*
* @var string
*/
define('DS', DIRECTORY_SEPARATOR);
/**
* 是否WIN系统
*
* @var boolean
*/
define('IS_WIN', DS==='\\'?true:false);
/**
* CRLF换行符
*
* @var string
*/
define('CRLF', "\r\n");
/**
* 服务器是否支持mbstring
*
* @var boolean
*/
define('IS_MBSTRING', extension_loaded('mbstring')?true:false);
/**
* 是否命令行执行
*
* @var boolean
*/
if (!defined('IS_CLI'))define('IS_CLI', (PHP_SAPI==='cli'));
/**
* 是否有NameSpace(PHP5.3及以上则为true,以下为False)
*
* @var boolean
*/
define('HAVE_NS', version_compare(PHP_VERSION,'5.3','>=')?true:false);
/**
* 是否系统调用模式
*
* @var boolean
*/
if (!defined('IS_SYSTEM_MODE'))define('IS_SYSTEM_MODE', !IS_CLI&&isset($_SERVER['HTTP_X_MYQEE_SYSTEM_HASH'])?true:false);
/**
* 站点目录
*
* @var string
*/
define('DIR_SYSTEM', realpath(dirname(__FILE__).DS.'..'.DS).DS);
/**
* Core目录
*
* @var string
*/
define('DIR_CORE', DIR_SYSTEM.'core'.DS);
/**
* 项目目录
*
* @var string
*/
define('DIR_PROJECT', DIR_SYSTEM.'projects'.DS);
/**
* 团队公用类库目录
*
* @var string
*/
define('DIR_TEAM_LIBRARY', DIR_SYSTEM.'team-library'.DS);
/**
* 第三方类库目录
*
* @var string
*/
define('DIR_LIBRARY', DIR_SYSTEM.'libraries'.DS);
/**
* 组件目录
*
* @var string
*/
define('DIR_MODULE', DIR_SYSTEM.'modules'.DS);
/**
* 第三方类库目录
*
* @var string
*/
define('DIR_VENDOR', DIR_SYSTEM.'vendor'.DS);
/**
* WWW目录
*
* @var string
*/
define('DIR_WWWROOT', DIR_SYSTEM.'wwwroot'.DS);
/**
* WWW目录
*
* @var string
*/
define('DIR_ASSETS', DIR_WWWROOT.'assets'.DS);
if (!isset($dir_data )) $dir_data = DIR_SYSTEM . 'data/';
if (!isset($dir_log )) $dir_log = $dir_data . 'log/';
if (!isset($dir_cache )) $dir_cache = $dir_data . 'cache/';
if (!isset($dir_upload)) $dir_upload = DIR_WWWROOT . 'upload/';
if (!isset($dir_temp )) $dir_temp = null;
/**
* 文件上传目录
*
* @var string
*/
define('DIR_UPLOAD', strpos($dir_upload,'://')!==false ? $dir_upload : (realpath($dir_upload)?realpath($dir_upload):DIR_WWWROOT.'upload').DS);
/**
* 数据目录
*
* @var string
*/
define('DIR_DATA', strpos($dir_data,'://')!==false ? $dir_data : (realpath($dir_data)?realpath($dir_data):DIR_SYSTEM.'data').DS);
/**
* Cache目录
*
* @var string
*/
define('DIR_CACHE', strpos($dir_cache,'://')!==false ? $dir_cache : (realpath($dir_cache)?realpath($dir_cache):DIR_DATA.'cache').DS);
/**
* Temp目录
*
* 默认用系统Temp目录
*
* @var string
*/
define('DIR_TEMP', strpos($dir_temp,'://')!==false ? $dir_temp : ($dir_temp && realpath($dir_temp)?realpath($dir_temp).DS:sys_get_temp_dir()));
/**
* Log目录
*
* @var string
*/
define('DIR_LOG', strpos($dir_log,'://')!==false ? $dir_log : (realpath($dir_log)?realpath($dir_log):DIR_DATA.'log').DS);
unset($dir_data, $dir_cache, $dir_log, $dir_temp);
/**
* 输出语言包
*
* [strtr](http://php.net/strtr) is used for replacing parameters.
*
* __('Welcome back, :user', array(':user' => $username));
*
* @uses I18n::get
* @param string text to translate
* @param array values to replace in the translated text
* @param string target language
* @return string
*/
function __($string, array $values = null)
{
static $have_i18n_class = false;
if ( false===$have_i18n_class )
{
$have_i18n_class = (boolean)class_exists('I18n', true);
}
if ($have_i18n_class)
{
$string = I18n::get($string);
}
return empty($values)?$string:strtr($string, $values);
}
/**
* 是否对传入参数转义,建议系统关闭自动转义功能
* @var boolean
*/
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
if (!IS_CLI && MAGIC_QUOTES_GPC)
{
function __stripcslashes($string)
{
if (is_array($string))
{
foreach ($string as $key => $val)
{
$string[$key] = __stripcslashes($val);
}
}
else
{
$string = stripcslashes($string);
}
return $string;
}
$_GET = __stripcslashes($_GET);
$_POST = __stripcslashes($_POST);
$_COOKIE = __stripcslashes($_COOKIE);
$_REQUEST = __stripcslashes($_REQUEST);
}
/**
* Include指定config文件的数据
*
* @param array $config
* @param string|array $files
*/
function __include_config_file(&$config, $__files__)
{
$__files__ = (array)$__files__;
foreach ($__files__ as $__file__)
{
include $__file__;
}
}
if (!function_exists('class_alias'))
{
/**
* 为一个类创建别名,模拟php5.3以后的 class_alias() 方法
*
* @param string $original
* @param string $alias
* @return boolean
*/
function class_alias($original, $alias)
{
if (!class_exists($original,true))
{
trigger_error("Class '{$original}' not found", E_USER_WARNING);
return false;
}
if (class_exists($alias,false))
{
trigger_error('First argument "'.$alias.'" of class_alias() must be a name of user defined class', E_USER_WARNING);
return false;
}
$rf = new ReflectionClass($original);
if ( $rf->isAbstract() )
{
$abs = 'abstract ';
}
else
{
$abs = '';
}
unset($rf);
eval($abs . 'class ' . $alias . ' extends ' . $original . ' {}');
return true;
}
}
/**
* Bootstrap
*
* @author 呼吸二氧化碳 <jonwang@myqee.com>
* @category Core
* @copyright Copyright (c) 2008-2013 myqee.com
* @license http://www.myqee.com/license.html
*/
abstract class Bootstrap
{
/**
* 包含目录
*
* @var array
*/
public static $include_path = array
(
'project' => array(), // 项目类库
'team-library' => array('default'=>DIR_TEAM_LIBRARY), // Team公共类库
'library' => array(), // 类库包
'core' => array('core'=>DIR_CORE), // 核心类库
);
/**
* 当前URL的根路径
*
* @var string
*/
public static $base_url = null;
/**
* 当前URL的PATH_INFO
*
* @var string
*/
public static $path_info = '/';
/**
* 当前项目
*
* @var string
*/
public static $project = 'default';
/**
* 当前项目目录
*
* @var string
*/
public static $project_dir;
/**
* 当前项目的URL
*
* @var string
*/
public static $project_url;
/**
* 系统文件列表
*
* @var array('project_name'=>array(...))
*/
public static $file_list = array();
/**
* 当前项目环境配置
*
* !!! 此配置会继承Core总配置,除projects和core节点
*
* @var array
*/
protected static $config = array();
/**
* Core总配置
*
* @var array
*/
protected static $core_config = array();
/**
* 目录设置
*
* @var array
*/
protected static $dir_setting = array
(
'class' => array('classes' , '.class'),
'controller' => array('controllers' , '.controller'),
'model' => array('models' , '.model'),
'orm' => array('orm' , '.orm'),
);
/**
* 系统初始化
*
* @param boolean $auto_execute 是否自动运行控制器
*/
public static function setup($auto_execute = true)
{
static $run = null;
if (!$run)
{
$run = true;
# PHP5.3 支持 composer 的加载
if (HAVE_NS && is_file(DIR_VENDOR.'autoload-for-myqee.php'))
{
try
{
require DIR_VENDOR.'autoload-for-myqee.php';
}
catch (Exception $e)
{
self::_show_error($e->getMessage());
}
$composer = true;
}
else
{
$composer = false;
}
/**
* 是否加载了Composer
*
* @var boolean
*/
define('IS_COMPOSER_LOADED', $composer);
# 注册自动加载类
spl_autoload_register(array('Bootstrap', 'auto_load'), true, true);
# 读取配置
if (!is_file(DIR_SYSTEM .'config'. EXT))
{
self::_show_error(__('Please rename the file config.new:EXT to config:EXT', array(':EXT'=>EXT)));
}
__include_config_file(self::$core_config, DIR_SYSTEM .'config'. EXT);
# 本地调试模式
if (isset(self::$core_config['local_debug_cfg']) && self::$core_config['local_debug_cfg'])
{
# 判断是否开启了本地调试
if (function_exists('get_cfg_var'))
{
$open_debug = get_cfg_var(self::$core_config['local_debug_cfg'])?1:0;
}
else
{
$open_debug = 0;
}
}
else
{
$open_debug = 0;
}
# 在线调试
if (self::_is_online_debug())
{
$open_debug = 1<<1 | $open_debug;
}
/**
* 是否开启DEBUG模式
*
* if (IS_DEBUG>>1)
* {
* //开启了在线调试
* }
*
* if (IS_DEBUG & 1)
* {
* //本地调试打开
* }
*
* if (IS_DEBUG)
* {
* // 开启了调试
* }
*
* @var int
*/
define('IS_DEBUG', $open_debug);
# Runtime配置
if (!isset(self::$core_config['runtime_config']))
{
self::$core_config['runtime_config'] = '';
}
else if (self::$core_config['runtime_config'] && !preg_match('#^[a-z0-9_]+$#', self::$core_config['runtime_config']))
{
self::$core_config['runtime_config'] = '';
}
if (self::$core_config['runtime_config'])
{
$runtime_file = DIR_SYSTEM .'config.'. self::$core_config['runtime_config'] .'.runtime'. EXT;
# 读取配置
if (is_file($runtime_file))
{
__include_config_file(self::$core_config, $runtime_file);
}
}
if (!IS_CLI)
{
# 输出文件头
header('Content-Type: text/html;charset=' . self::$core_config['charset']);
}
// 设置错误等级
if (isset(self::$core_config['error_reporting']))
{
@error_reporting(self::$core_config['error_reporting']);
}
// 时区设置
if (isset(self::$core_config['timezone']))
{
@date_default_timezone_set(self::$core_config['timezone']);
}
//获取全局$project变量
global $project, $admin_mode;
if (isset($project) && $project)
{
$project = (string)$project;
if (!isset(self::$core_config['projects'][$project]))
{
self::_show_error(__('not found the project: :project', array(':project'=>$project)));
}
// 如果有设置项目
self::$project = $project;
// 管理员模式
if (isset($admin_mode) && true===$admin_mode)
{
$request_mode = 'admin';
}
}
else
{
if (IS_CLI)
{
if (!isset($_SERVER["argv"]))
{
exit('Err Argv');
}
if (isset($_SERVER['OS']) && $_SERVER['OS']=='Windows_NT')
{
# 切换到UTF-8编码显示状态
exec('chcp 65001');
}
$argv = $_SERVER["argv"];
//$argv[0]为文件名
if (isset($argv[1]) && $argv[1] && isset(self::$core_config['projects'][$argv[1]]))
{
self::$project = $argv[1];
}
array_shift($argv); //将文件名移除
array_shift($argv); //将项目名移除
self::$path_info = trim(implode('/', $argv));
unset($argv);
}
else
{
$request_mode = '';
self::setup_by_url($request_mode);
}
}
if ( isset(self::$core_config['projects'][self::$project]['isuse']) && !self::$core_config['projects'][self::$project]['isuse'] )
{
self::_show_error(__('the project: :project is not open.', array(':project'=>$project)));
}
/**
* 初始项目名
*
* @var string
*/
define('INITIAL_PROJECT_NAME', self::$project);
/**
* 是否后台模式
*
* @var boolean
*/
if (!defined('IS_ADMIN_MODE'))define('IS_ADMIN_MODE', (!IS_CLI && $request_mode=='admin')?true:false);
/**
* 是否RestFul模式
*
* @var boolean
*/
if (!defined('IS_REST_MODE'))define('IS_REST_MODE', (!IS_CLI && $request_mode=='rest')?true:false);
/**
* 静态文件URL地址前缀
*
* @var string
*/
define('URL_ASSETS', isset(self::$core_config['url']['assets']) && self::$core_config['url']['assets']?self::$core_config['url']['assets']:'/assets/' );
$project_dir = DIR_PROJECT . self::$project . DS;
if (!is_dir($project_dir))
{
self::_show_error(__('not found the project: :project', array(':project' => self::$project)));
}
self::$include_path['project'] = array(self::$project=>$project_dir);
# 加载类库
self::reload_all_libraries();
}
Core::setup($auto_execute);
}
/**
* 自动加载类
*
* @param string $class_name
* @return boolean
*/
public static function auto_load($class_name)
{
if (class_exists($class_name, false))return true;
# 移除两边的
$class_name = strtolower(trim($class_name, '\\ '));
$class_name_array = explode('_', $class_name, 2);
$is_alias = false;
if ($class_name_array[0]=='core' && count($class_name_array)==2)
{
# 系统类库
$ns = 'core';
$new_class_name = $class_name_array[1];
}
else if ($class_name_array[0]=='ex')
{
# 扩展别名
$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]);
$new_class_name = $m[2];
}
else if (preg_match('#^module_(.*)$#', $class_name, $m))
{
# Module 组件
$ns = 'module';
list($ns_name) = explode('_', $m[1], 2);
$new_class_name = $m[1];
}
else
{
$ns = '';
$new_class_name = $class_name;
}
# 获取类的前缀
$prefix = '';
$new_class_arr = explode('_', $new_class_name, 2);
if (2===count($new_class_arr))
{
$prefix = $new_class_arr[0];
}
if ($prefix && isset(self::$dir_setting[$prefix]))
{
$dir_setting = self::$dir_setting[$prefix];
$class_file_name = $new_class_arr[1];
if ($prefix=='controller')
{
if (IS_SYSTEM_MODE)
{
$dir_setting[0] .= '-system';
}
elseif (IS_CLI)
{
$dir_setting[0] .= '-shell';
}
elseif (IS_ADMIN_MODE)
{
$dir_setting[0] .= '-admin';
}
elseif (IS_REST_MODE)
{
$dir_setting[0] .= '-rest';
}
}
}
else
{
$dir_setting = self::$dir_setting['class'];
$class_file_name = $new_class_name;
}
if ($ns)
{
if ($ns=='core')
{
$file = DIR_CORE;
}
elseif ($ns=='module')
{
$file = DIR_MODULE . $ns_name . DS;
}
else
{
$file = DIR_LIBRARY . $ns_name . DS;
}
$file .= $dir_setting[0] . DS . str_replace('_', DS, $class_file_name) . $dir_setting[1] . EXT;
if (is_file($file))
{
require $file;
}
}
else
{
if (!$is_alias)
{
# 在include path中找
foreach (array('project', 'team-library') as $type)
{
foreach (self::$include_path[$type] as $path)
{
$tmp_file = $path . $dir_setting[0] . DS . $class_file_name . $dir_setting[1] . EXT;
if (is_file($tmp_file))
{
require $tmp_file;
if (class_exists($class_name, false))return true;
}
}
}
}
# 没有找到文件且为项目类库,尝试在某个命名空间的类库中寻找
static $module_dir = array();
list($tmp_prefix) = explode('_', $new_class_name, 2);
if (!isset($module_dir[$tmp_prefix]))
{
$module_dir[$tmp_prefix] = is_dir(DIR_MODULE .$tmp_prefix. DS);
}
$include_path = self::$include_path;
$include_path['module'] = array();
if ($module_dir[$tmp_prefix])
{
# 生成一个module路径,比如 Database_Driver_MySQL 就是在 module/database 中
$include_path['module'] = array
(
'module' => DIR_MODULE .$tmp_prefix. DS,
);
}
foreach (array('library', 'module', 'core') as $type)
{
foreach ($include_path[$type] as $lib_ns=>$path)
{
$ns_class_name = ($type=='library'?'library_':'') . str_replace('.', '_', $lib_ns) . '_' . $new_class_name;
if (self::auto_load($ns_class_name))
{
if (!$is_alias && class_exists($class_name, false))
{
# 在加载$ns_class_name时,当前需要的类库有可能被加载了,直接返回true
return true;
}
else
{
class_alias($ns_class_name, $class_name);
}
break;
}
}
}
}
if (class_exists($class_name, false))
{
return true;
}
else
{
return false;
}
}
/**
* 获取包含目录,返回一个一维的数组
*
* ! 注意 Bootstrap::$include_path 为一个2维数组
*
* @return array
*/
public static function include_path()
{
$arr = array();
foreach (self::$include_path as $v)
{
foreach ($v as $p)
{
$arr[] = $p;
}
}
return $arr;
}
/**
* 查找文件
*
* //查找一个视图文件
* Bootstrap::find_file('views','test',EXT);
*
* @param string $dir 目录
* @param string $file 文件
* @param string $ext 后缀 例如:.html,不指定(null)的话则自动设置后缀
* @param boolean $auto_require 是否自动加载上来,对config,i18n无效
* @return string
*/
public static function find_file($dir, $file, $ext=null, $auto_require=false)
{
# 处理后缀
if (null===$ext)
{
$the_ext = EXT;
}
elseif (false===$ext || ''===$ext)
{
$the_ext = '';
}
elseif ($ext[0]!='.')
{
$the_ext = '.'.$ext;
}
# 是否只需要寻找到第一个文件
$only_need_one_file = true;
if ($dir == 'classes')
{
$file = strtolower(str_replace('_', '/', $file));
if (null===$ext)$the_ext = '.class' . EXT;
}
else if ($dir == 'models')
{
$file = strtolower(str_replace('_', '/', $file));
if (null===$ext)$the_ext = '.model' . EXT;
}
else if ( $dir == 'controllers' )
{
$file = strtolower(str_replace('_', '/', $file));
if (null===$ext)$the_ext = '.controller' . EXT;
if (IS_SYSTEM_MODE)
{
$dir .= '-system';
}
elseif (IS_CLI)
{
$dir .= '-shell';
}
elseif (IS_ADMIN_MODE)
{
$dir .= '-admin';
}
elseif (IS_REST_MODE)
{
$dir .= '-rest';
}
}
elseif ($dir=='i18n' || $dir=='config')
{
if (null===$ext)$the_ext = '.lang';
$only_need_one_file = false;
}
elseif ($dir=='views')
{
if (null===$ext)$the_ext = '.view' . EXT;
$file = strtolower($file);
}
elseif ($dir == 'orm')
{
if (null===$ext)$the_ext = '.orm' . EXT;
#orm
$file = preg_replace('#^(.*)_[a-z0-9]+$#i', '$1', $file);
$file = strtolower(str_replace('_', '/', $file));
}
# 寻找到的文件
$found_files = array();
# 采用当前项目目录
$include_path = self::$include_path;
foreach ($include_path as $the_path)
{
foreach ($the_path as $path)
{
$tmpfile = $path . $dir . DS . $file . $the_ext;
if (is_file($tmpfile))
{
$found_files[] = $tmpfile;
if ($only_need_one_file) break;
}
}
}
if ($found_files)
{
if ($only_need_one_file)
{
if ($auto_require)
{
require $found_files[0];
}
return $found_files[0];
}
else
{
return $found_files;
}
}
}
/**
* 导入指定类库
* 支持多个,当一次导入多个时,从数组最后一个开始导入
*
* 导入的格式必须是类似 com.a.b 的形式,否则会抛出异常,例如: com.myqee.test
*
* Bootstrap::import_library('com.myqee.test');
* Bootstrap::import_library(array('com.myqee.test','com.myqee.cms'));
*
* @param string|array $library_name 指定类库 支持多个
* @return num 返回新加载的类库总数
*/
public static function import_library($library_name)
{
if (!$library_name)return false;
$library_name = (array)$library_name;
# 反向排序,从最后一个开始导入
$library_name = array_reverse($library_name);
$config_files = array();
$load_num = 0;