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;
|
2021-08-11 01:04:57 +08:00
|
|
|
use Kiri\Abstracts\Component;
|
|
|
|
|
use Kiri\Kiri;
|
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
|
|
|
{
|
2021-08-11 01:04:57 +08:00
|
|
|
$logger = Kiri::app()->getLogger();
|
2021-02-20 17:30:03 +08:00
|
|
|
$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
|
|
|
|
|
|
|
|
}
|