Bootstrap.php
2.79 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
<?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('config', $this->_config);
defined('WEBSITE_DOMAIN_URL') || define('WEBSITE_DOMAIN_URL', $this->_config->website->domain);
$pathList = array(
$this->_config->application->brightKnight,
$this->_config->application->framework
);
set_include_path(implode(PATH_SEPARATOR, $pathList));
}
public function _initQin(Yaf_Dispatcher $dispatcher)
{
############################ Begin 配置 ############################
$_qinConfig = ''; //ini_get('qin.config');
$_environment = ini_get('qin.environment');
defined('Q_APPLICATION_ENV') || define('Q_APPLICATION_ENV', $_environment);
if (empty($_qinConfig)) {
$_qinConfig = $this->_config->application->servers->config;
}
defined('QIN_CONFIG') || define('QIN_CONFIG', $_qinConfig);
defined('Q_DS') || define('Q_DS', DIRECTORY_SEPARATOR);
$_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);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
}
############################ End 配置 ############################
}
public function _initNamespaces()
{
Yaf_Loader::getInstance()->registerLocalNameSpace(array('QLib', 'QLibConfigs', 'QLibView', 'QModels', 'Adminx'));
}
public function _initPlugin(Yaf_Dispatcher $dispatcher)
{
$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 _initLayout(Yaf_Dispatcher $dispatcher)
{
if (!$dispatcher->getRequest()->isXmlHttpRequest()) {
$layoutPath = $this->_config->application->layout->path;
$layout = new QLib_Layout($layoutPath);
$dispatcher->setView($layout);
}
}
}