-
Notifications
You must be signed in to change notification settings - Fork 7
/
Aweapp.php
53 lines (46 loc) · 2.04 KB
/
Aweapp.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
<?php
class Aweapp extends CWebApplication {
public $config;
public $punish = 0;
public function __construct($config = null) {
$this->config = $config;
parent::__construct($config);
// register_shutdown_function(array($this, 'shutdown'));
}
public function shutdown() {
if (YII_ENABLE_ERROR_HANDLER && ($error = error_get_last())) {
$this->handleError($error['type'], $error['message'], $error['file'], $error['line']);
die();
}
}
protected function init() {
$modulesConfig = array();
//dynamically loading modules and their config
foreach (glob(dirname(__FILE__) . '/protected/modules/*', GLOB_ONLYDIR) as $moduleDirectory) {
$this->setModules(array(basename($moduleDirectory)));
$configFile = $moduleDirectory . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'main.php';
if (file_exists($configFile))
$modulesConfig = CMap::mergeArray($modulesConfig, require ($configFile));
}
$finalConfig = CMap::mergeArray($modulesConfig, require (dirname(__FILE__) . '/protected/config/db.php'));
$this->configure(CMap::mergeArray($finalConfig, require($this->config)));
return parent::init();
}
public function runController($route) {
if (($ca = $this->createController($route)) !== null) {
list($controller, $actionID) = $ca;
$oldController = $this->controller;
$this->controller = $controller;
$controller->init();
$controller->run($actionID);
$this->controller = $oldController;
} else {
//we only forgive once
if ($this->punish) {
Yii::app()->getErrorHandler()->showError(new CHttpException(404, Yii::t('yii', 'Unable to resolve the request "{route}".', array('{route}' => $route === '' ? $this->defaultController : $route))));
}
$this->punish++;
Yii::app()->getErrorHandler()->parsePath($route);
}
}
}