mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 05:35:09 +08:00
43 lines
953 B
PHP
43 lines
953 B
PHP
<?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;
|
|
|
|
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);
|
|
}
|
|
}
|