150 lines
2.7 KiB
PHP
150 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Core;
|
|
|
|
use App\Models\User\User;
|
|
use App\Models\Account\Account;
|
|
use Illuminate\Support\Facades\App;
|
|
use App\Exceptions\NotExistException;
|
|
use App\Domains\App\Services\AppService;
|
|
use App\Domains\Auth\Services\UserAuthService;
|
|
use App\Domains\Auth\Services\AdminAuthService;
|
|
use App\Domains\Account\Services\AccountService;
|
|
|
|
/**
|
|
* Application/Account/User/Config 全局代理
|
|
*/
|
|
class Dipper
|
|
{
|
|
/**
|
|
* 站点实例
|
|
*
|
|
* @var App
|
|
*/
|
|
public $application;
|
|
|
|
/**
|
|
* 账号实例
|
|
*
|
|
* @var Account
|
|
*/
|
|
public $account;
|
|
|
|
/**
|
|
* 用户实例
|
|
*
|
|
* @var User
|
|
*/
|
|
public $user;
|
|
|
|
/**
|
|
* 配置实例
|
|
*
|
|
* @var array
|
|
*/
|
|
public $config;
|
|
|
|
/**
|
|
* 初始化站点
|
|
*
|
|
* @param string $key
|
|
* @param boolean $force
|
|
* @return App
|
|
*/
|
|
public function initApplication($key, $force = false)
|
|
{
|
|
if ($this->application) {
|
|
return $this->application;
|
|
}
|
|
|
|
if (!$key || !$this->application = app(AppService::class)->init($key, $force)) {
|
|
throw new NotExistException('应用不存在或已被删除');
|
|
} elseif ($this->application->status != 0) {
|
|
throw new NotExistException('应用已被屏蔽所有功能, 无法使用');
|
|
}
|
|
|
|
return $this->application;
|
|
}
|
|
|
|
/**
|
|
* 初始化后端用户
|
|
*
|
|
* @param string $key
|
|
* @param boolean $force
|
|
* @return Account
|
|
*/
|
|
public function initAccount()
|
|
{
|
|
if ($this->account) {
|
|
return $this->account;
|
|
}
|
|
|
|
return app('auth:admin')->authenticate();
|
|
}
|
|
|
|
/**
|
|
* 初始化前端用户
|
|
*
|
|
* @param string $key
|
|
* @param boolean $force
|
|
* @return User
|
|
*/
|
|
public function initUser()
|
|
{
|
|
if ($this->user) {
|
|
return $this->user;
|
|
}
|
|
|
|
return app('auth:user')->authenticate();
|
|
}
|
|
|
|
/**
|
|
* 获取站点配置
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getConfig($key = null)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* 设置站点配置
|
|
*
|
|
* @param string $key;
|
|
* @param string|array $value;
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function setConfig($key, $value)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Set 账号实例
|
|
*
|
|
* @param Account $account 账号实例
|
|
*
|
|
* @return self
|
|
*/
|
|
public function setAccount(Account $account)
|
|
{
|
|
$this->account = $account;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set 用户实例
|
|
*
|
|
* @param User $user 用户实例
|
|
*
|
|
* @return self
|
|
*/
|
|
public function setUser(User $user)
|
|
{
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
}
|
|
}
|