zm
2021-03-25 d84ff6053b22269a6c59dc005e9efb8de6595988
commit | author | age
90c639 1 <?php
Z 2 /**
3  * Created by PhpStorm
4  * User: 风哀伤
5  * Date: 2020/11/24
6  * Time: 10:14 上午
7  * @copyright: ©2020 浙江禾匠信息科技
8  * @link: http://www.zjhejiang.com
9  */
10
11 namespace app\jobs;
12
13 use yii\base\BaseObject;
14
15 class BaseJob extends BaseObject
16 {
17     public $hostInfo;
18     public $baseUrl;
19
20     public function __construct($config = [])
21     {
22         parent::__construct($config);
23         if (\Yii::$app instanceof \yii\web\Application) {
24             if (!$this->hostInfo) {
25                 $this->hostInfo = \Yii::$app->request->hostInfo;
26             }
27             if (!$this->baseUrl) {
28                 $this->baseUrl = \Yii::$app->request->baseUrl;
29             }
30         } else {
31             if (!$this->hostInfo) {
32                 $this->hostInfo = \Yii::$app->hostInfo;
33             }
34             if (!$this->baseUrl) {
35                 $this->baseUrl = \Yii::$app->baseUrl;
36             }
37         }
38         $this->setRequest();
39     }
40
41     public function setRequest()
42     {
43         \Yii::$app->setHostInfo($this->hostInfo);
44         \Yii::$app->setBaseUrl($this->baseUrl);
45     }
46 }