2023-03-10 18:29:41 +08:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* ApiStyleService.php@HDK-Core
|
|
|
|
|
*
|
|
|
|
|
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
|
|
|
|
* Powered by PhpStorm
|
|
|
|
|
* Created on 2023/3/10
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Singularity\HDK\Core\Service;
|
|
|
|
|
|
|
|
|
|
use Hyperf\Context\Context;
|
|
|
|
|
|
2023-06-19 18:16:41 +08:00
|
|
|
use function Hyperf\Config\config;
|
|
|
|
|
|
2023-03-10 18:29:41 +08:00
|
|
|
class ApiStyleService
|
|
|
|
|
{
|
|
|
|
|
public const RESTFUL = 'restful';
|
|
|
|
|
public const CLASSIC = 'classic';
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
Context::set(self::class, config('common.response.restful') ? self::RESTFUL : self::CLASSIC);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-14 18:29:05 +08:00
|
|
|
/**
|
|
|
|
|
* @param literal-string $style
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function set(string $style): static
|
2023-03-10 18:29:41 +08:00
|
|
|
{
|
|
|
|
|
Context::set(self::class, $style === self::RESTFUL ? self::RESTFUL : self::CLASSIC);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get(): string
|
|
|
|
|
{
|
2023-03-13 13:32:48 +08:00
|
|
|
return Context::get(self::class) ?? (config('common.response.restful')
|
|
|
|
|
? ApiStyleService::RESTFUL
|
|
|
|
|
: ApiStyleService::CLASSIC);
|
2023-03-10 18:29:41 +08:00
|
|
|
}
|
2023-03-14 18:29:05 +08:00
|
|
|
}
|