php-json-rpc/src/Server/JsonRpcServerDoc.php
2019-01-17 14:10:18 +08:00

53 lines
1.1 KiB
PHP

<?php
namespace JsonRpc\Server;
use itxq\apidoc\BootstrapApiDoc;
class JsonRpcDoc
{
protected $config;
protected $classes;
public function __construct($config)
{
$this->map = include $config['map'];
}
public function methods()
{
$methods = [];
foreach ($this->map as $key => $item) {
if (!in_array($item[0], $methods)) {
$methods[] = $item[0];
}
}
return $methods;
}
public function render()
{
$config = [
'class' => $this->methods(),
'filter_method' => [],
];
$api = new BootstrapApiDoc($config);
$doc = $api->getHtml();
exit($doc);
}
protected function desc($class, $method)
{
if (!isset($this->classes[$class])) {
$reflector = new \ReflectionClass($class);
$this->classes[$class] = $reflector;
} else {
$reflector = $this->classes[$class];
}
return str_replace("/**\n",'',$reflector->getMethod($method)->getDocComment());
}
}