zm
2021-03-25 d84ff6053b22269a6c59dc005e9efb8de6595988
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
<?php
/**
 * Created by PhpStorm
 * User: 风哀伤
 * Date: 2020/11/24
 * Time: 10:14 上午
 * @copyright: ©2020 浙江禾匠信息科技
 * @link: http://www.zjhejiang.com
 */
 
namespace app\jobs;
 
use yii\base\BaseObject;
 
class BaseJob extends BaseObject
{
    public $hostInfo;
    public $baseUrl;
 
    public function __construct($config = [])
    {
        parent::__construct($config);
        if (\Yii::$app instanceof \yii\web\Application) {
            if (!$this->hostInfo) {
                $this->hostInfo = \Yii::$app->request->hostInfo;
            }
            if (!$this->baseUrl) {
                $this->baseUrl = \Yii::$app->request->baseUrl;
            }
        } else {
            if (!$this->hostInfo) {
                $this->hostInfo = \Yii::$app->hostInfo;
            }
            if (!$this->baseUrl) {
                $this->baseUrl = \Yii::$app->baseUrl;
            }
        }
        $this->setRequest();
    }
 
    public function setRequest()
    {
        \Yii::$app->setHostInfo($this->hostInfo);
        \Yii::$app->setBaseUrl($this->baseUrl);
    }
}