commit | author | age
|
2207d6
|
1 |
<?php |
W |
2 |
/** |
|
3 |
* @copyright ©2018 浙江禾匠信息科技 |
|
4 |
* @author Lu Wei |
|
5 |
* @link http://www.zjhejiang.com/ |
|
6 |
* Created by IntelliJ IDEA |
|
7 |
* Date Time: 2018/10/30 12:00 |
|
8 |
*/ |
|
9 |
|
|
10 |
namespace app\core; |
|
11 |
|
|
12 |
|
|
13 |
/*** |
|
14 |
* Class Application |
|
15 |
* @package app\core |
|
16 |
*/ |
|
17 |
class ConsoleApplication extends \yii\console\Application |
|
18 |
{ |
|
19 |
use Application; |
|
20 |
|
|
21 |
/** |
|
22 |
* Application constructor. |
|
23 |
* @param null $config |
|
24 |
* @throws \yii\base\InvalidConfigException |
|
25 |
* @throws \Exception |
|
26 |
*/ |
|
27 |
public function __construct($config = null) |
|
28 |
{ |
|
29 |
$this->checkEnv() |
|
30 |
->loadDotEnv() |
|
31 |
->defineConstants(); |
|
32 |
|
|
33 |
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; |
|
34 |
|
|
35 |
if (!$config) { |
|
36 |
$config = require __DIR__ . '/../config/console.php'; |
|
37 |
} |
|
38 |
|
|
39 |
parent::__construct($config); |
|
40 |
|
|
41 |
$this->enableObjectResponse() |
|
42 |
->enableErrorReporting(); |
|
43 |
|
|
44 |
$this->loadAppLogger() |
|
45 |
->loadAppHandler() |
|
46 |
->loadPluginsHandler(); |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* 检查服务器php环境 |
|
51 |
* @return $this |
|
52 |
* @throws \Exception |
|
53 |
*/ |
|
54 |
protected function checkEnv() |
|
55 |
{ |
|
56 |
$checkFunctions = [ |
|
57 |
'proc_open', |
|
58 |
'proc_get_status', |
|
59 |
]; |
|
60 |
if (version_compare(PHP_VERSION, '7.2.0') < 0) { |
|
61 |
throw new \Exception('PHP版本不能小于7.2,当前PHP版本为' . PHP_VERSION); |
|
62 |
} |
|
63 |
foreach ($checkFunctions as $function) { |
|
64 |
if (!function_exists($function)) { |
|
65 |
throw new \Exception('PHP函数' . $function . '已被禁用,请先取消禁用' . $function . '函数'); |
|
66 |
} |
|
67 |
} |
|
68 |
return $this; |
|
69 |
} |
|
70 |
|
|
71 |
public function getSession() |
|
72 |
{ |
|
73 |
return \Yii::$app->session; |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
} |