mirror of
https://github.com/flarum/framework.git
synced 2025-01-20 05:32:49 +08:00
Add Route extender for registering routes with forum, admin or API
This commit is contained in:
parent
1d47047d45
commit
8d049126d0
49
src/Extend/Route.php
Normal file
49
src/Extend/Route.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* 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)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user