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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use HttpServer\Abstracts\HttpService;
|
|
|
|
|
use Snowflake\Snowflake;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Application
|
|
|
|
|
* @package HttpServer
|
|
|
|
|
*/
|
|
|
|
|
class Application extends HttpService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $message
|
|
|
|
|
* @param string $category
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
protected function write($message, $category = 'app')
|
|
|
|
|
{
|
2020-09-03 11:39:20 +08:00
|
|
|
$logger = Snowflake::app()->logger;
|
2020-08-31 01:27:08 +08:00
|
|
|
$logger->write($message, $category);
|
|
|
|
|
$logger->insert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-17 14:09:14 +08:00
|
|
|
* @param $name
|
2020-08-31 01:27:08 +08:00
|
|
|
* @return mixed
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2020-12-17 14:09:14 +08:00
|
|
|
public function __get($name): mixed
|
2020-08-31 01:27:08 +08:00
|
|
|
{
|
2020-12-17 14:09:14 +08:00
|
|
|
if (method_exists($this, $name)) {
|
|
|
|
|
return $this->{$name}();
|
2020-08-31 01:27:08 +08:00
|
|
|
}
|
2020-12-17 14:09:14 +08:00
|
|
|
$handler = 'get' . ucfirst($name);
|
2020-08-31 01:27:08 +08:00
|
|
|
if (method_exists($this, $handler)) {
|
|
|
|
|
return $this->{$handler}();
|
|
|
|
|
}
|
2020-12-17 14:09:14 +08:00
|
|
|
if (property_exists($this, $name)) {
|
|
|
|
|
return $this->$name;
|
2020-08-31 01:27:08 +08:00
|
|
|
}
|
2020-12-17 14:09:14 +08:00
|
|
|
$message = sprintf('method %s::%s not exists.', get_called_class(), $name);
|
2020-08-31 01:27:08 +08:00
|
|
|
throw new Exception($message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|