Bootstrap.php
4.26 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
<?php
/**
* @name Bootstrap
* @author liuziyang
* @desc 所有在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用,
* @see http://www.php.net/manual/en/class.yaf-bootstrap-abstract.php
* 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher
* 调用的次序, 和申明的次序相同
*/
class Bootstrap extends Yaf_Bootstrap_Abstract
{
private $_config;
public function _initConfig(Yaf_Dispatcher $dispatcher)
{
define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod()));
$this->_config = Yaf_Application::app()->getConfig();
Yaf_Registry::set('configs', $this->_config);
}
public function _initQin(Yaf_Dispatcher $dispatcher)
{
############################ Begin 配置 ############################
$_config = ini_get('qin.configs');
$_environment = ini_get('qin.environment');
defined('Q_APPLICATION_ENV') || define('Q_APPLICATION_ENV', $_environment);
if (empty($_config)) {
switch (Q_APPLICATION_ENV) {
case Q_Core_Consts::Q_APPLICATION_ENV_LOCALING :
$_config = '/Data/code/QF1.1/Framework/Config';
break;
case Q_Core_Consts::Q_APPLICATION_ENV_TESTING :
$_config = '/Data/code/QF1.1/Framework/Config';
break;
case Q_Core_Consts::Q_APPLICATION_ENV_RELEASE :
$_config = '/Data/code/QF1.1/Framework/Config';
break;
}
}
defined('QIN_CONFIG') || define('QIN_CONFIG', $_config);
$_qdebug = $dispatcher->getRequest()->getQuery('_qdebug');
if (Q_APPLICATION_ENV != Q_Core_Consts::Q_APPLICATION_ENV_RELEASE || (!empty($_qdebug) && $_qdebug == 'display_errors')) {
error_reporting(E_ALL & ~E_NOTICE | E_STRICT);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
}
############################ End 配置 ############################
}
public function _initNamespaces()
{
Yaf_Loader::getInstance()->registerLocalNameSpace(array('QLib', 'QLibConfigs', 'QLibView'));
}
public function _initModules(Yaf_Dispatcher $dispatcher)
{
$app = $dispatcher->getApplication();
$modules = $app->getModules();
foreach ($modules as $module) {
if (strcmp($module, 'Index') == 0) continue;
require_once $app->getAppDirectory() . "/modules/{$module}/__init.php";
}
}
public function _initPlugin(Yaf_Dispatcher $dispatcher)
{
//注册一个插件
//$objSamplePlugin = new SamplePlugin();
//$dispatcher->registerPlugin($objSamplePlugin);
$dispatcher->registerPlugin(new QLib_Plugin_Routes());
}
public function _initRoute(Yaf_Dispatcher $dispatcher)
{
$config = new Yaf_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
if (isset($config->routes)) {
$dispatcher->getRouter()->addConfig($config->routes);
}
}
public function _initMobile(Yaf_Dispatcher $dispatcher)
{
if ($_SERVER['HTTP_HOST'] == 'item.yohobuy.com') {
return true;
}
if ($_SERVER['HTTP_HOST'] == 'list.yohobuy.com' && substr_compare($_SERVER['REQUEST_URI'], '/item/item/goods', 0, 16, true) == 0) {
return true;
}
$uri = $_SERVER['REQUEST_URI'];
if (QINLib_Mobile::isMobile() && $_SERVER['HTTP_HOST'] == 'huodong.yohobuy.com' && empty($_COOKIE['m2w'])) {
header("HTTP/1.1 301 Moved Permanently");
header('Location:http://m.yohobuy.com'. $uri);
exit;
}
QINLib_Mobile::toMobile();
}
public function _initView(Yaf_Dispatcher $dispatcher)
{
}
public function _initLayout(Yaf_Dispatcher $dispatcher)
{
if (!$dispatcher->getRequest()->isXmlHttpRequest()) {
$layoutPath = $this->_config->application->layout->path;
$layout = new QLib_Layout($layoutPath);
$dispatcher->setView($layout);
}
}
public function _initDefaultName(Yaf_Dispatcher $dispatcher)
{
//$dispatcher->setDefaultModule("Search")->setDefaultController("Index")->setDefaultAction("index");
}
}