diff --git a/framework/core/src/Extend/Api.php b/framework/core/src/Extend/Api.php new file mode 100644 index 000000000..616f2d07f --- /dev/null +++ b/framework/core/src/Extend/Api.php @@ -0,0 +1,35 @@ +routes[] = compact('method', 'url', 'name', 'action'); + + return $this; + } + + public function extend(Container $container) + { + if ($container->make('type') !== 'api') { + return; + } + + if (count($this->routes)) { + $routes = $container->make('flarum.api.routes'); + + foreach ($this->routes as $route) { + $method = $route['method']; + $routes->$method($route['url'], $route['name'], function (ServerRequestInterface $httpRequest, $routeParams) use ($container, $route) { + $action = $container->make($route['action']); + + return $action->handle($httpRequest, $routeParams); + }); + } + } + } +}