Request
+ +Result:
--}} + + {{--{{$result}}
--}}
+ {{--diff --git a/src/Providers/LumenServerServiceProvider.php b/src/Providers/LumenServerServiceProvider.php index e487751..2e91aad 100644 --- a/src/Providers/LumenServerServiceProvider.php +++ b/src/Providers/LumenServerServiceProvider.php @@ -2,7 +2,9 @@ namespace JsonRpc\Providers; +use App\Http\Middleware\JsonRpc; use Illuminate\Support\ServiceProvider; +use JsonRpc\Server\JsonRpcDoc; use JsonRpc\Server\JsonRpcServer; use JsonRpc\Server\JsonRpcTool; use Laravel\Lumen\Application; @@ -41,13 +43,18 @@ class LumenServerServiceProvider extends ServiceProvider if (function_exists('env') && env('APP_DEBUG')) { $tool = function () use ($config) { - $doc = new JsonRpcTool($config); - return $doc->render(); + $tool = new JsonRpcTool($config); + return $tool->render(); }; $this->app->router->get('tool.html', $tool); $this->app->router->post('tool.html', $tool); + $this->app->router->get('doc.html', function () use ($config) { + $doc = new JsonRpcDoc($config); + return $doc->render(); + }); + } }); } diff --git a/src/Server/JsonRpcServerDoc.php b/src/Server/JsonRpcServerDoc.php index 2d455b8..2db5e61 100644 --- a/src/Server/JsonRpcServerDoc.php +++ b/src/Server/JsonRpcServerDoc.php @@ -5,21 +5,55 @@ namespace JsonRpc\Server; class JsonRpcDoc { - protected $methods = []; + protected $config; - public function __construct($dir) + protected $classes; + + public function __construct($config) { - $this->methods = include $dir . '/methods.php'; + $this->map = include $config['map']; } public function methods() { - return $this->methods; + $methods = []; + foreach ($this->map as $key => $item) { + $methods[] = [ + 'method' => $key, + 'desc' => $this->desc($item[0], $item[1]), + ]; + } + return $methods; } public function render() { - return view('doc', ['doc' => $this]); + + /** + * @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()); } } \ No newline at end of file diff --git a/src/views/doc.blade.php b/src/views/doc.blade.php new file mode 100644 index 0000000..3320ca9 --- /dev/null +++ b/src/views/doc.blade.php @@ -0,0 +1,106 @@ + +
+{{$result}}
--}}
+ {{--