/
omni.class.php
executable file
·89 lines (72 loc) · 2.53 KB
/
omni.class.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
<?php
/**
* Created by PhpStorm.
* User: lost
* Date: 14-7-28
* Time: 下午2:05
* 统管启动执行类
*/
use core\Process;
use core\Configure;
use core\Cache;
use core\DB;
use core\Fpm;
use interfaces\IStartup;
class Omni {
private $_config = null;
private static $_instance = null;
private $_startup;
private function __construct(){
$this->base_init();
$mode = php_sapi_name();
switch($mode){
case 'cli' :
$this->cli_init();
break;
default: $this->fpm_init();
}
}
static function instance(){
if(self::$_instance == null)
self::$_instance = new Omni();
return self::$_instance;
}
/**
* 通用初始化
*/
private function base_init(){
spl_autoload_register(array('Autoload','load'));
$this->_config = Configure::instance();
$this->_config->load(array('common'));
$this->cache = Cache::instance( $this->_config->common['memcache']);
}
private function cli_init(){
$maps = require(BASE_PATH.'/conf/process.inc.php');
$this->db = new DB('deamon');
$this->_startup = Process::instance($maps);
}
private function fpm_init(){
/*数据库初始化**/
$init_db = $this->_config->common['init_db'] ;
if( $init_db != '' )
$this->db = new DB($init_db);
/*html模板初始化**/
$this->tpl = new Smarty();
$this->tpl->caching = $this->_config->common['smarty']['cache_enable'];
$this->tpl->setTemplateDir(BASE_PATH . '/' .BASE_PROJECT . $this->_config->common['smarty']['template_dir']);
$this->tpl->setCompileDir(BASE_PATH . '/' .BASE_PROJECT . $this->_config->common['smarty']['compile_dir']);
$this->tpl->setCacheDir(BASE_PATH . '/' .BASE_PROJECT . $this->_config->common['smarty']['cache_dir']);
$this->tpl->left_delimiter = $this->_config->common['smarty']['left_delimiter'];
$this->tpl->right_delimiter = $this->_config->common['smarty']['right_delimiter'];
/*运行pathinfo 解析**/
$this->_startup = Fpm::instance();
}
/**
* 执行 同一入口只运行一次
* @param string $dir 入口文件所在文件夹名称
*/
function run($dir = null){
if($this->_startup instanceof IStartup)
$this->_startup->run($dir);
}
}