This commit is contained in:
54
app/Context/ApiUrlContext.php
Normal file
54
app/Context/ApiUrlContext.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/7/11
|
||||
* Time: 下午9:00
|
||||
* Description:
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Context;
|
||||
|
||||
use Hyperf\Context\Context;
|
||||
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/7/11
|
||||
* Time: 下午9:00
|
||||
* Description: ApiUrlContext. 请求url上下文
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
class ApiUrlContext
|
||||
{
|
||||
private const string API_URL_KEY = 'api_url';
|
||||
|
||||
public static function setApiUrl(string $apiUrl): void
|
||||
{
|
||||
Context::set(self::API_URL_KEY, $apiUrl);
|
||||
}
|
||||
|
||||
public static function getApiUrl(): ?string
|
||||
{
|
||||
return Context::get(self::API_URL_KEY);
|
||||
}
|
||||
|
||||
public static function clearApiUrl(): void
|
||||
{
|
||||
Context::set(self::API_URL_KEY, null);
|
||||
}
|
||||
|
||||
public static function hasApiUrl(): bool
|
||||
{
|
||||
return Context::has(self::API_URL_KEY);
|
||||
}
|
||||
}
|
@ -44,25 +44,6 @@ class QueueContext
|
||||
return Context::get(self::USER_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前公司信息
|
||||
* @param array $companyInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function setCompanyInfo(array $companyInfo): void
|
||||
{
|
||||
Context::set(self::COMPANY_KEY, $companyInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前公司信息
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getCompanyInfo(): ?array
|
||||
{
|
||||
return Context::get(self::COMPANY_KEY);
|
||||
}
|
||||
|
||||
public static function clear(): void
|
||||
{
|
||||
Context::destroy(self::USER_KEY);
|
||||
|
@ -35,7 +35,7 @@ class UserContext
|
||||
public static function setCurrentUser(array|string|int $user): void
|
||||
{
|
||||
$companyRepository = make(FirstCompanyRepository::class);
|
||||
if (!empty($companyInfo = $companyRepository->getCompanyByFullName($user['user']['full_name']))) {
|
||||
if (!empty($companyInfo = $companyRepository->getCompanyByFullName($user['full_name'], false))) {
|
||||
$user['company'] = $companyInfo;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user