Files
kiri-core/Rpc/Consumer.php
T

54 lines
716 B
PHP
Raw Normal View History

2021-04-01 17:41:32 +08:00
<?php
namespace Rpc;
2021-04-01 17:42:42 +08:00
use Annotation\Inject;
2021-04-01 17:41:32 +08:00
use Exception;
use Snowflake\Snowflake;
/**
* Class Consumer
* @package Rpc
*/
abstract class Consumer implements IProducer
{
2021-04-01 18:02:46 +08:00
2021-04-01 17:42:42 +08:00
protected ?Client $client = null;
#[Inject('rpc')]
public ?Producer $rpc = null;
2021-04-01 17:41:32 +08:00
2021-04-01 18:02:46 +08:00
/**
* @return Client|null
*/
public function initClient(): ?Client
{
return $this->client;
}
2021-04-01 17:41:32 +08:00
/**
* @param string $name
* @return mixed
* @throws Exception
*/
public function __get(string $name): mixed
{
if (property_exists($this, $name)) {
return $this->$name;
}
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->{$method}();
}
return Snowflake::app()->get($name);
}
}