PHP code example of jetea / ctx
1. Go to this page and download the library: Download jetea/ctx library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jetea / ctx example snippets
$this->ctx->模块名->方法()
ctx 根文件夹
├── Ctx.php Ctx入口类
├── Basic/ 文件夹
│ └── Ctx.php 各个Ctx服务基类
└── Service/ Service文件夹,包括所有的服务模块
└── Example/ 服务模块1:Example模块
└── Ctx.php 服务模块入口
├── Child/ 模块子类文件夹
│ └── Demo.php 模块子类
└── Example2/ 服务模块2:Example2模块
├── Child/
│ └── Demo.php
└── Ctx.php
namespace Ctx;
use Jetea\Ctx\Ctx as BasicCtx;
/**
* Class Ctx
* @property \Ctx\Service\Example\Ctx $Example
*/
class Ctx extends BasicCtx
{
/**
* ctx 实例
*/
protected static $ctxInstance;
//ctx 命名空间
protected $ctxNamespace = 'Ctx';
}
ctx ctx根文件夹
├── Ctx.php Ctx入口类
├── Basic/ 文件夹
└── Service/ Service文件夹,包括所有的服务模块
ctx_1 ctx_1根文件夹
├── Ctx.php Ctx入口类
├── Basic/ 文件夹
└── Service/ Service文件夹,包括所有的服务模块
namespace Ctx\Basic;
use Jetea\Ctx\Basic\Ctx as BasicCtx;
/**
* Class Ctx
* @package Ctx\Basic
*
* @property \Ctx\Ctx $ctx
*/
abstract class Ctx extends BasicCtx
{
protected function invokeRpc($method, $args)
{
// $this->rpc['host'],
// $this->getModName(),
// $method,
// var_export($args, true)
}
}
namespace Ctx\Service\Example;
use Ctx\Basic\Ctx as BasicCtx;
/**
* 模块接口声明文件
* 备注:文件命名跟模块中的其他类不同,因为模块入口类只能被实例化一次
* 也就是只能用ctx->模块 来实例化,不能用loadC来实例化更多
*/
class Ctx extends BasicCtx
{
}
$this->ctx->模块->方法()
/**
* rpc配置
*/
protected $rpc = [
'host' => '', //网关地址
'method' => [], //方法名 减少无用的远程调用
];