From e0f61d51c009cf7ca13ad2f9239516488dbf0723 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 3 Jan 2018 23:18:19 +0100 Subject: [PATCH] Add Route extender for registering routes with forum, admin or API --- framework/core/src/Extend/Route.php | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 framework/core/src/Extend/Route.php diff --git a/framework/core/src/Extend/Route.php b/framework/core/src/Extend/Route.php new file mode 100644 index 000000000..260bb37a5 --- /dev/null +++ b/framework/core/src/Extend/Route.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extend; + +use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; +use Illuminate\Contracts\Container\Container; + +class Route implements Extender +{ + protected $appName; + protected $name; + protected $httpMethod; + protected $path; + protected $handler; + + public function __construct($appName, $name, $httpMethod, $path, $handler) + { + $this->appName = $appName; + $this->name = $name; + $this->httpMethod = $httpMethod; + $this->path = $path; + $this->handler = $handler; + } + + public function apply(Container $container) + { + /** @var RouteCollection $routes */ + $collection = $container->make("flarum.{$this->appName}.routes"); + + /** @var RouteHandlerFactory $factory */ + $factory = $container->make(RouteHandlerFactory::class); + + $collection->{$this->httpMethod}( + $this->path, + $this->name, + $factory->toController($this->handler) + ); + } +}