Files
xk-api-yii/common/core/BackendApplication.php
2024-09-19 11:32:39 +08:00

97 lines
2.0 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: chatfeed
* Date: 2022/5/21
* Time: 2:34 PM
*/
namespace common\core;
use common\handlers\HandlerBase;
use common\handlers\HandlerRegister;
use yii\base\Exception;
use yii\web\Application;
/**
* @property \yii\web\Request $request
*/
class BackendApplication extends Application
{
public $mallId = 0;
//public $supplierId = 0;
protected $mall;
private $hostInfo;
private $baseUrl;
public function __construct($config = null)
{
parent::__construct($config);
$this->loadAppHandler();
}
/**
* @return $this
*/
protected function loadAppHandler()
{
$register = new HandlerRegister();
$HandlerClasses = $register->getHandlers();
foreach ($HandlerClasses as $HandlerClass) {
$handler = new $HandlerClass();
if ($handler instanceof HandlerBase) {
/** @var HandlerBase $handler */
$handler->register();
}
}
return $this;
}
public function setMall($mall)
{
$this->mall = $mall;
}
public function getMall()
{
if(!$this->mall){
$mallId = $this->mallId;
if(!$mallId){
throw new Exception('门店不存在');
}
$mall = Mall::findOne($mallId);
if(!$mall){
throw new Exception('门店不存在');
}
$this->mall = $mall;
}
return $this->mall;
}
public function getHostInfo()
{
if ($this->hostInfo) {
return $this->hostInfo;
}
return '';
}
public function setHostInfo($hostInfo)
{
$this->hostInfo = $hostInfo;
}
public function getBaseUrl()
{
if ($this->baseUrl) {
return $this->baseUrl;
}
return '';
}
public function setBaseUrl($baseUrl)
{
$this->baseUrl = $baseUrl;
}
}