* Powered by PhpStorm * Created on 2023/3/10 */ namespace Singularity\HDK\Core\Service; use Hyperf\Context\Context; use function Hyperf\Config\config; 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); } /** * @param literal-string $style * @return $this */ public function set(string $style): static { Context::set(self::class, $style === self::RESTFUL ? self::RESTFUL : self::CLASSIC); return $this; } public function get(): string { return Context::get(self::class) ?? (config('common.response.restful') ? ApiStyleService::RESTFUL : ApiStyleService::CLASSIC); } }