-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
1619 lines (1407 loc) · 48.8 KB
/
bootstrap.php
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());
/**
* 系统当前时间
*
* @var int
*/
define('TIME', time());
/**
* 目录分隔符简写
*
* @var string
*/
define('DS', DIRECTORY_SEPARATOR);
/**
* 站点目录
*
* @var string
*/
define('DIR_SYSTEM', realpath(__DIR__.DS.'..'.DS).DS);
/**
* Application目录
*
* @var string
*/
define('DIR_APPLICATION', DIR_SYSTEM.'application'.DS);
/**
* APP应用目录
*
* @var string
*/
define('DIR_APPS', DIR_SYSTEM.'apps'.DS);
/**
* Data目录
*
* @var string
*/
define('DIR_DATA', DIR_SYSTEM.'data'.DS);
/**
* 项目目录
*
* @var string
*/
define('DIR_PROJECT', DIR_SYSTEM.'projects'.DS);
/**
* Cache目录
*
* @var string
*/
define('DIR_CACHE', DIR_DATA.'cache'.DS);
/**
* Temp目录
*
* @var string
*/
define('DIR_TEMP', DIR_DATA.'temp'.DS);
/**
* Log目录
*
* @var string
*/
define('DIR_LOG', DIR_DATA.'log'.DS);
/**
* 系统类库目录
*
* @var string
*/
define('DIR_CORE', DIR_SYSTEM.'core'.DS);
/**
* 模块目录
*
* @var string
*/
define('DIR_LIBRARY', DIR_SYSTEM.'libraries'.DS);
/**
* WWW目录
*
* @var string
*/
define('DIR_WWWROOT', DIR_SYSTEM.'wwwroot'.DS);
/**
* WWW目录
*
* @var string
*/
define('DIR_ASSETS', DIR_WWWROOT.'assets'.DS);
/**
* 是否命令行执行
*
* @var boolean
*/
define('IS_CLI',(PHP_SAPI==='cli'));
/**
* 是否系统内部调用模式
*
* @var boolean
*/
define('IS_SYSTEM_MODE', !IS_CLI && isset($_SERVER['HTTP_X_MYQEE_SYSTEM_HASH']) ? true : false);
/**
* 是否命令行执行
*
* @var boolean
*/
define('IS_WIN',(DS==='\\'));
/**
* PHP后缀
*
* @var string
*/
define('EXT', '.php');
/**
* CRLF换行符
*
* @var string
*/
define('CRLF', "\r\n");
/**
* 服务器是否支持mbstring
*
* @var boolean
*/
define('IS_MBSTRING',extension_loaded('mbstring')?true:false);
/**
* 输出语言包
*
* [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);
}
/**
* Bootstrap
*
* @author jonwang(jonwang@myqee.com)
* @category Core
* @copyright Copyright (c) 2008-2012 myqee.com
* @license http://www.myqee.com/license.html
*/
final class Bootstrap
{
/**
* 版本号
*
* @var float
*/
const VERSION = '2.0.2';
/**
* 包含目录
*
* @var array
*/
public static $include_path = array
(
'\\' => DIR_APPLICATION,
'\\core\\' => DIR_CORE,
);
/**
* 配置
*
* @var array
*/
public static $config = array();
/**
* 当前URL的根路径
*
* @var string
*/
public static $base_url = null;
/**
* 当前URL的PATH_INFO
*
* @var string
*/
public static $path_info = null;
/**
* 当前项目
*
* @var string
*/
public static $project = null;
/**
* 当前应用
*
* @var string
*/
public static $app = null;
/**
* 目录设置
*
* @var array
*/
private 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;
# 注册自动加载类
spl_autoload_register(array('Bootstrap','auto_load'));
# 读取配置
if (!is_file(DIR_SYSTEM.'config'.EXT))
{
self::show_error('Please rename the file config.new.php to config.php');
}
$include_config_file = function ( & $config, $file )
{
include $file;
};
self::$config = array
(
'core' => array()
);
# 读取主配置
$include_config_file( self::$config['core'] , DIR_SYSTEM.'config'.EXT );
# 读Debug配置
if ( isset(self::$config['core']['debug_config']) && self::$config['core']['debug_config'] && is_file(DIR_SYSTEM.'debug.config'.EXT) )
{
$include_config_file( self::$config['core'] , DIR_SYSTEM.'debug.config'.EXT );
}
# DEBUG配置
if ( isset(self::$config['core']['local_debug_cfg']) && self::$config['core']['local_debug_cfg'] )
{
if ( function_exists( 'get_cfg_var' ) )
{
$open_debug = get_cfg_var( self::$config['core']['local_debug_cfg'] ) ? 1 : 0;
}
else
{
$open_debug = 0;
}
}
else
{
$open_debug = 0;
}
/**
* 判断是否开启了在线调试
*
* @return boolean
*/
$is_online_debug = function ()
{
if ( IS_SYSTEM_MODE )
{
if ( isset($_SERVER['HTTP_X_MYQEE_SYSTEM_DEBUG']) && $_SERVER['HTTP_X_MYQEE_SYSTEM_DEBUG']=='1' )
{
return true;
}
else
{
return false;
}
}
if (!isset($_COOKIE['_debug_open'])) return false;
if (!isset(Bootstrap::$config['core']['debug_open_password'])) return false;
if (!is_array(Bootstrap::$config['core']['debug_open_password']))return false;
foreach ( Bootstrap::$config['core']['debug_open_password'] as $user=>$pass )
{
if ($_COOKIE['_debug_open'] == Bootstrap::get_debug_hash($user,$pass))
{
return true;
}
}
return false;
};
if ( $is_online_debug() )
{
$open_debug == 1<<1 | $open_debug;
}
unset($is_online_debug);
/**
* 是否开启DEBUG模式
*
* if (IS_DEBUG>>1)
* {
* //开启了在线调试
* }
*
* if (IS_DEBUG & 1)
* {
* //本地调试打开
* }
*
* if (IS_DEBUG)
* {
* // 开启了调试
* }
*
* @var int
*/
define('IS_DEBUG', $open_debug);
# 请求模式
$request_mode = '';
if (IS_CLI)
{
if ( !isset($_SERVER["argv"]) )
{
exit('Err Argv');
}
$argv = $_SERVER["argv"];
//$argv[0]为文件名
if ( isset($argv[1]) && $argv[1] && isset(self::$config['core']['projects'][$argv[1]]) )
{
self::$project = $argv[1];
}
array_shift($argv); //将文件名移除
array_shift($argv); //将项目名移除
self::$path_info = trim(implode('/', $argv));
unset($argv);
}
else
{
self::setup_by_url($request_mode);
if (isset(self::$config['core']['charset']))
{
# 输出文件头
header('Content-Type: text/html;charset='.self::$config['core']['charset']);
}
}
# 设置页面错误等级
if (isset(self::$config['core']['error_reporting']))
{
error_reporting(self::$config['core']['error_reporting']);
}
# 设置时区
if (isset(self::$config['core']['timezone']) && self::$config['core']['timezone'])
{
date_default_timezone_set(self::$config['core']['timezone']);
}
/**
* 加载类库
* @var array $arr
*/
$load_library = function($arr)
{
# 逆向排序
rsort($arr);
foreach ($arr as $library_name)
{
if (!$library_name)continue;
try
{
Bootstrap::import_library($library_name);
}
catch (Exception $e)
{
Bootstrap::show_error($e->getMessage());
}
}
};
/**
* 是否后台模式
*
* @var boolean
*/
define('IS_ADMIN_MODE',(!IS_CLI && $request_mode=='admin')?true:false);
if (IS_SYSTEM_MODE)
{
# 设置控制器在[system]目录下
self::$dir_setting['controller'][0] .= DS.'[system]';
}
# 如果有autoload目录,则设置加载目录
if ( isset(self::$config['core']['libraries']['autoload']) && is_array(self::$config['core']['libraries']['autoload']) && self::$config['core']['libraries']['autoload'] )
{
$load_library(self::$config['core']['libraries']['autoload']);
}
if (IS_CLI)
{
# cli模式
if ( isset(self::$config['core']['libraries']['cli']) && is_array(self::$config['core']['libraries']['cli']) && self::$config['core']['libraries']['cli'] )
{
$load_library(self::$config['core']['libraries']['cli']);
}
if (!IS_SYSTEM_MODE)
{
# 控制器在[shell]目录下
self::$dir_setting['controller'][0] .= DS.'[shell]';
}
}
elseif (IS_ADMIN_MODE)
{
# 后台模式
if ( isset(self::$config['core']['libraries']['admin']) && is_array(self::$config['core']['libraries']['admin']) && self::$config['core']['libraries']['admin'] )
{
$load_library(self::$config['core']['libraries']['admin']);
}
if (!IS_SYSTEM_MODE)
{
# 控制器在[admin]目录下
self::$dir_setting['controller'][0] .= DS.'[admin]';
}
}
elseif ($request_mode=='app')
{
# APP模式
if ( isset(self::$config['core']['libraries']['app']) && is_array(self::$config['core']['libraries']['app']) && self::$config['core']['libraries']['app'] )
{
$load_library(self::$config['core']['libraries']['app']);
}
}
if (IS_DEBUG)
{
# 加载debug类库
if ( isset(self::$config['core']['libraries']['debug']) && is_array(self::$config['core']['libraries']['debug']) && self::$config['core']['libraries']['debug'] )
{
$load_library(self::$config['core']['libraries']['debug']);
}
# 输出服务器信息
Core::debug()->info('SERVER IP:' . $_SERVER["SERVER_ADDR"] . (function_exists('php_uname')?'. SERVER NAME:' . php_uname('a') : ''));
# 输出Include Path
Core::debug()->group( 'include path' );
foreach ( self::$include_path as $value )
{
Core::debug()->log( Core::debug_path( $value ) );
}
Core::debug()->groupEnd();
if (self::$project)
{
Core::debug()->info('project: '.self::$project);
}
elseif ($request_mode=='app')
{
Core::debug()->info('app mode');
}
else
{
Core::debug()->info('default application');
}
if (IS_ADMIN_MODE)
{
Core::debug()->info('admin mode');
}
}
unset($load_library);
Core::setup();
}
# 直接执行
if ($auto_execute)
{
if ( IS_CLI || IS_SYSTEM_MODE )
{
self::execute(self::$path_info);
}
else
{
ob_start();
try
{
self::execute(self::$path_info);
}
catch (Exception $e)
{
$code = $e->getCode();
if ( 404===$code || E_PAGE_NOT_FOUND===$code )
{
Core::show_404($e->getMessage());
}
elseif (500===$code)
{
Core::show_500($e->getMessage());
}
else
{
Core::show_500($e->getMessage(),$code);
}
}
HttpIO::$body = ob_get_clean();
}
# 全部全部连接
Core::close_all_connect();
}
}
/**
* 执行指定URI的控制器
*
* @param string $uri
*/
public static function execute($uri)
{
$found = self::find_controller($uri);
if ($found)
{
require $found['file'];
$class_name = $found['namespace'].$found['class'];
if (class_exists($class_name,false))
{
$controller = new $class_name();
Controller::$controllers[] = $controller;
$rm_controoler = function () use ($controller)
{
foreach (Controller::$controllers as $k=>$c)
{
if ($c===$controller)unset(Controller::$controllers[$k]);
}
Controller::$controllers = array_values(Controller::$controllers);
};
$arguments = $found['args'];
if ($arguments)
{
$action = current($arguments);
if (0===strlen($action))
{
$action = 'default';
}
}
else
{
$action = 'index';
}
$action_name = 'action_'.$action;
if (!method_exists($controller,$action_name))
{
if ($action_name!='action_default' && method_exists($controller,'action_default'))
{
$action_name='action_default';
}
elseif (method_exists($controller,'__call'))
{
$controller->__call($action_name,$arguments);
$rm_controoler();
return;
}
else
{
$rm_controoler();
throw new Exception(__('Page Not Found'),404);
}
}
else
{
array_shift($arguments);
}
$ispublicmethod = new ReflectionMethod($controller,$action_name);
if (!$ispublicmethod->isPublic())
{
$rm_controoler();
throw new Exception(__('Request Method Not Allowed.'),405);
}
unset($ispublicmethod);
# 将参数传递给控制器
$controller->action = $action_name;
$controller->controller = $found['class'];
$controller->ids = $found['ids'];
if (IS_SYSTEM_MODE)
{
# 系统内部调用参数
$controller->arguments = @unserialize(HttpIO::POST('data',HttpIO::PARAM_TYPE_OLDDATA));
}
else
{
$controller->arguments = $arguments;
}
# 前置方法
if (method_exists($controller,'before'))
{
$controller->before();
}
# 执行方法
$count_arguments = count($arguments);
switch ($count_arguments)
{
case 0:
$controller->$action_name();
break;
case 1:
$controller->$action_name($arguments[0]);
break;
case 2:
$controller->$action_name($arguments[0], $arguments[1]);
break;
case 3:
$controller->$action_name($arguments[0], $arguments[1], $arguments[2]);
break;
case 4:
$controller->$action_name($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
break;
default:
call_user_func_array(array($controller, $action_name), $arguments);
break;
}
# 后置方法
if (method_exists($controller,'after'))
{
$controller->after();
}
# 移除控制器
$rm_controoler();
}
else
{
throw new Exception(__('Page Not Found'),404);
}
}
else
{
throw new Exception(__('Page Not Found'),404);
}
}
/**
* 自动加载类
*
* @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,'\\'));
# 通过正则匹配出相关参数
if (preg_match('#^(?:(core|library|project)\\\\(?:([0-9a-z_]+)\\\\([0-9a-z_]+)\\\\)?)?(?:(orm|controller|model)_)?([0-9a-z_]+)$#i', $class_name,$m))
{
# 主命名空间,包括 core,library,project
$lib_space = $m[1];
# 子命名空间,例如 MyQEE\Test\
$sub_name_space = '';
if ($m[2] && $m[3])
{
$sub_name_space = $m[2].'\\'.$m[3].'\\';
}
$class_prefix = 'class';
# 命名空间内的类名称
$the_classname = $real_name = $m[5];
if ($m[4])
{
# 前缀,目前包括orm,controller,model,其它均被视为类库
$class_prefix = $m[4];
$the_classname = $class_prefix.'_'.$the_classname;
}
if ($class_prefix=='orm')
{
# ORM需要处理下,去掉后缀
$real_name = @preg_replace('#^(.*)_(data|finder|index|result)$#', '$1',$real_name);
}
if ( $class_prefix=='controller' )
{
# 控制器是2个下划线代表一个文件夹
$filename = str_replace('__', DS, $real_name);
}
else
{
$filename = str_replace('_', DS, $real_name);
}
}
else
{
# 不在既定的命名规则之内
return false;
}
static $lib_dir_array = array
(
'' => DIR_APPLICATION,
'library' => DIR_LIBRARY,
'core' => DIR_CORE,
'project' => DIR_PROJECT,
);
/*
Controller\Index DIR_APPLICATION/controller/index.controller.php
Database\Driver\MySQL DIR_APPLICATION/classes/database/driver/mysql.class.php
Model\Test\Abc DIR_APPLICATION/model/test/abc.model.php
Library\MyQEE\CMS\Test DIR_LIBRARY/myqee/cms/classes/test.class.php
Core\Test\t DIR_CORE/classes/test/t.class.php
*/
# 拼接出完整的文件路径
$file = str_replace('\\',DS,$sub_name_space).self::$dir_setting[$class_prefix][0].DS.$filename.self::$dir_setting[$class_prefix][1].EXT;
if ( is_file($lib_dir_array[$lib_space].$file) )
{
# 指定文件存在
require $lib_dir_array[$lib_space].$file;
}
elseif ($lib_space==='')
{
# 没有找到文件且为项目类库,尝试在某个命名空间的类库中寻找
foreach (self::$include_path as $ns=>$path)
{
if ($ns=='\\')continue;
$ns_class_name = $ns.$the_classname;
if ( self::auto_load($ns_class_name) )
{
if ( class_exists($class_name,false) )
{
# 在加载$ns_class_name时,当前需要的类库有可能被加载了,直接返回true
return true;
}
else
{
# 是否禁用eval方式加载
static $disable_eval = null;
if (null===$disable_eval)$disable_eval = isset(self::$config['core']['disable_eval']) && self::$config['core']['disable_eval'] ? true:false;
if ( $disable_eval )
{
if ( substr($ns,0,9)=='\\library\\' )
{
$dir = 'libraries'.DS.substr($ns,9);
}
else
{
$dir = $ns;
}
$tmp_file = DIR_SYSTEM . trim(str_replace('\\',DS,$dir),DS) . DS . ($sub_name_space?str_replace('\\', DS, $sub_name_space) . DS : '') . 'extend_files' . DS . $file;
if ( is_file($tmp_file) )
{
include $tmp_file;
}
}
else
{
$rf = new ReflectionClass($ns_class_name);
if ( $rf->isAbstract() )
{
$abstract = 'abstract ';
}
else
{
$abstract = '';
}
unset($rf);
$str = 'namespace '.trim($lib_space.'\\'.$sub_name_space,'\\').'{'.$abstract.'class '.$the_classname.' extends '.$ns_class_name.'{}}';
# 动态执行
eval($str);
}
}
break;
}
}
}
if ( class_exists($class_name,false) )
{
return true;
}
else
{
return false;
}
}
/**
* 查找文件
*
* //查找一个视图文件
* Bootstrap::find_file('views','test',EXT);
*
* @param string $dir 目录
* @param string $file 文件
* @param string $ext 后缀 例如:.html,不指定(null)的话则自动设置后缀
* @return string
*/
public static function find_file($dir, $file, $ext=null)
{
$dir = trim($dir);
$file = str_replace(array('/','\\'),DS,trim($file,' /\\.'));
// 没有指定后缀
if (null===$ext)
{
switch ($dir)
{
case 'views':
$ext = '.view'.EXT;
break;
case 'classes':
$ext = EXT;
break;
case 'modles':
$ext = '.modle'.EXT;
break;
case 'orm':
$ext = '.orm'.EXT;
break;
case 'controllers':
$ext = '.controller'.EXT;
break;
case 'i18n':
$ext = '.lang';
break;
default:
$ext = '';
break;
}
}
else if ($ext && $ext[0]!='.')$ext='.'.$ext;
# 控制器目录比较特殊,不同模式所在文件夹不一样
if ('controllers'==$dir)
{
$dir = self::$dir_setting['controller'][0];
}
foreach (self::$include_path as $path)
{
$tmpfile = $path.$dir.DS.$file.$ext;
if ( is_file($tmpfile) )
{
return $tmpfile;
}
}
}
/**
* 导入指定类库
*
* 导入的格式必须是类似 com.a.b 的形式,否则会抛出异常,例如: com.myqee.test
*
* //导入myqee.test类库
* Bootstrap::import_library('com.myqee.test');
*
* @param string $library_name 指定类库
* @return boolean
*/
public static function import_library($library_name)
{
if (!$library_name) return false;
$library_name = strtolower(trim($library_name));
if (substr($library_name,0,4)!='com.')return false;
$library_name = str_replace('.', '\\',substr($library_name,4));
$ns = '\\library\\'.$library_name.'\\';
if ( !isset(self::$include_path[$ns]) )
{
$dir = DIR_LIBRARY.str_replace('\\', DS, $library_name).DS;
if (is_dir($dir))
{
if (self::$project)
{
$appliction = array
(
'\\project\\'.self::$project.'\\' => array_shift(self::$include_path),
'\\' => array_shift(self::$include_path),
);
}
else