Files
kiri-core/HttpServer/Abstracts/HttpService.php
T

54 lines
973 B
PHP
Raw Normal View History

2020-08-31 01:27:08 +08:00
<?php
2020-10-29 18:17:25 +08:00
declare(strict_types=1);
2020-08-31 01:27:08 +08:00
namespace HttpServer\Abstracts;
2021-02-20 17:30:03 +08:00
use Exception;
2020-08-31 01:27:08 +08:00
use Snowflake\Abstracts\Component;
2021-02-20 17:30:03 +08:00
use Snowflake\Snowflake;
2020-08-31 01:27:08 +08:00
2021-02-20 17:30:03 +08:00
/**
* Class HttpService
* @package HttpServer\Abstracts
*/
2020-08-31 01:27:08 +08:00
abstract class HttpService extends Component
{
2021-02-20 17:30:03 +08:00
/**
* @param $message
* @param string $category
* @throws Exception
*/
2021-07-08 17:36:28 +08:00
protected function write($message, string $category = 'app')
2021-02-20 17:30:03 +08:00
{
$logger = Snowflake::app()->getLogger();
$logger->write($message, $category);
$logger->insert();
}
/**
* @param $name
* @return mixed
* @throws Exception
*/
public function __get($name): mixed
{
if (method_exists($this, $name)) {
return $this->{$name}();
}
$handler = 'get' . ucfirst($name);
if (method_exists($this, $handler)) {
return $this->{$handler}();
}
if (property_exists($this, $name)) {
return $this->$name;
}
2021-04-25 11:27:13 +08:00
$message = sprintf('method %s::%s not exists.', static::class, $name);
2021-02-20 17:30:03 +08:00
throw new Exception($message);
}
2020-08-31 01:27:08 +08:00
}