-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
73 lines (69 loc) · 2.54 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
<?php
/**
* @link http://www.tintsoft.com/
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd.
* @license http://www.tintsoft.com/license/
*/
namespace yuncms\core;
use Yii;
use yii\base\Event;
use yii\base\BootstrapInterface;
use yii\web\Application as WebApplication;
use yii\console\Application as ConsoleApplication;
use yii\web\Cookie;
/**
* Class Bootstrap
* @package yuncms\core
*/
class Bootstrap implements BootstrapInterface
{
/**
* @inheritdoc
*/
public function bootstrap($app)
{
if ($app instanceof ConsoleApplication) {
$app->controllerMap['corn'] = [
'class' => 'yuncms\core\console\controllers\CronController',
];
// $app->controllerMap['migrate'] = [
// 'class' => 'yii\console\controllers\MigrateController',
// 'templateFile' => '@yuncms/core/console/views/migration.php',
// //'migrationNamespaces' => $migrationNamespaces,
// ];
//全局任务程序注册
if (is_file(__DIR__ . '../tasks.php')) {
$tasks = require(__DIR__ . '../tasks.php');
foreach ($tasks as $task) {
if (isset($task['class'])) {
Event::on($task['class'], $task['event'], $task['callback']);
} else {
Event::on($task[0], $task[1], $task[2]);
}
}
}
}
// else if($app instanceof WebApplication){
// //自动检测语言
// if (($language = Yii::$app->request->getQueryParam('language')) !== null) {
// $app->language = $language;
// Yii::$app->response->cookies->add(new Cookie(['name' => 'language', 'value' => $language]));
// } else if (($cookie = Yii::$app->request->cookies->get('language')) !== null) {
// $app->language = $cookie->value;
// } else if (($language = Yii::$app->request->getPreferredLanguage()) !== null) {
// $app->language = $language;
// }
// }
//全局事件处理程序注册
if (is_file(__DIR__ . '../events.php')) {
$events = require(__DIR__ . '../events.php');
foreach ($events as $event) {
if (isset($event['class'])) {
Event::on($event['class'], $event['event'], $event['callback']);
} else {
Event::on($event[0], $event[1], $event[2]);
}
}
}
}
}