php-json-rpc/src/Server/JsonRpcServerDoc.php

59 lines
1.2 KiB
PHP
Raw Normal View History

2019-01-05 03:25:30 +00:00
<?php
namespace JsonRpc\Server;
class JsonRpcDoc
{
2019-01-07 07:32:24 +00:00
protected $config;
2019-01-05 03:25:30 +00:00
2019-01-07 07:32:24 +00:00
protected $classes;
public function __construct($config)
2019-01-05 03:25:30 +00:00
{
2019-01-07 07:32:24 +00:00
$this->map = include $config['map'];
2019-01-05 03:25:30 +00:00
}
public function methods()
{
2019-01-07 07:32:24 +00:00
$methods = [];
foreach ($this->map as $key => $item) {
$methods[] = [
'method' => $key,
'desc' => $this->desc($item[0], $item[1]),
];
}
return $methods;
2019-01-05 03:25:30 +00:00
}
public function render()
{
2019-01-07 07:32:24 +00:00
/**
* @var $view Factory
*/
$view = view();
dump($this->methods());
exit;
$view->share('methods', $this->methods());
return $view->exists('doc') ?
$view->make('doc') :
$view->file(__DIR__ . '/../views/doc.blade.php');
}
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());
2019-01-05 03:25:30 +00:00
}
}