Skip to content

Commit

Permalink
Merge pull request #3 from bzeron/master
Browse files Browse the repository at this point in the history
update comment
  • Loading branch information
sh7ning authored Feb 5, 2020
2 parents 71016ed + d30a989 commit e284240
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
28 changes: 17 additions & 11 deletions src/Basic/Ctx.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ abstract class Ctx
/**
* 命名空间
* 辅助方法有setNamespace() 和 getNamespace()
* @var string
*/
private $namespace = '';

/**
* @return string
*/
final public function getNamespace()
{
return $this->namespace;
Expand All @@ -31,9 +35,13 @@ final public function getNamespace()
/**
* 模块名
* 辅助方法有setModName() 和 getModName()
* @var string
*/
private $modName = '';

/**
* @return string
*/
final public function getModName()
{
return $this->modName;
Expand All @@ -44,9 +52,9 @@ final public function getModName()
*
* 不采用反射实现,是因为已知可以直接传递,减少计算量
*
* @param $namespace
* @param $modName
* @throws Exception
* @param string $namespace
* @param string $modName
* @return void
*/
final public function initCtxService($namespace, $modName)
{
Expand All @@ -63,6 +71,7 @@ final public function initCtxService($namespace, $modName)

/**
* 模块具体执行的初始化方法
* @return void
*/
protected function init()
{
Expand All @@ -77,7 +86,6 @@ protected function init()
* @param $class
* @param $args
* @return static|object
* @throws Exception
*/
final protected function loadC($class, ...$args)
{
Expand All @@ -101,11 +109,9 @@ final protected function loadC($class, ...$args)
/**
* 远程Rpc调用
*
* @param $method
* @param $args
*
* @param string $method
* @param array $args
* @return mixed
* @throws Exception
*/
public function __call($method, $args)
{
Expand All @@ -119,6 +125,7 @@ public function __call($method, $args)

/**
* rpc配置
* @var array
*/
protected $rpc = [
'host' => '', //网关地址
Expand All @@ -128,9 +135,8 @@ public function __call($method, $args)
/**
* 执行远程Rpc调用逻辑,方便子类进行更灵活的操作如:显式调用,异步调用等
*
* @param $method
* @param $args
*
* @param string $method
* @param array $args
* @return mixed
*/
protected function invokeRpc($method, $args)
Expand Down
7 changes: 4 additions & 3 deletions src/Ctx.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ private function __clone()
/**
* 框架单例,静态变量保存全局实例
* @description 这里设置为private,是为了让该静态属性必须被继承,且必须为 protected
* @var static
*/
private static $ctxInstance;

/**
* 请求单例
*
* @return static
*/
public static function getInstance()
Expand All @@ -47,11 +47,13 @@ public static function getInstance()
* 采用继承,而不采用反射提高性能
* $thisReflection = new ReflectionClass($this);
* $this->ctxNamespace = $thisReflection->getNamespaceName();
* @var string
*/
protected $ctxNamespace;

/**
* 私有构造函数,防止外界实例化对象
* Ctx constructor.
*/
protected function __construct()
{
Expand All @@ -61,9 +63,8 @@ protected function __construct()
* 自动单例获取ctx服务框架的模块
* 模块接口文件必须是单例,防止错误的调用模块接口
*
* @param $m string 模块名 模块名首字母必须大写
* @param string $m 模块名 模块名首字母必须大写
* @return mixed
* @throws Exception
*/
public function __get($m)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author sh7ning
* @version 0.0.1
*/
class Exception extends \Exception
class Exception extends \RuntimeException
{
/**
* Exception constructor.
Expand Down
6 changes: 4 additions & 2 deletions tests/ctx/Ctx.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
class Ctx extends BasicCtx
{
/**
* ctx instance
* @var static
*/
protected static $ctxInstance;

//ctx namespace
/**
* @var string
*/
protected $ctxNamespace = 'Tests\Jetea\Ctx';
}

0 comments on commit e284240

Please sign in to comment.