mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 23:23:52 +08:00
Revert "Frontend extender: Remove route registration"
This reverts commit df6f10da20
.
This commit is contained in:
parent
5d44b6f259
commit
52b5bdcf4e
|
@ -14,6 +14,7 @@ namespace Flarum\Extend;
|
|||
use Flarum\Extension\Extension;
|
||||
use Flarum\Frontend\Asset\ExtensionAssets;
|
||||
use Flarum\Frontend\CompilerFactory;
|
||||
use Flarum\Http\RouteHandlerFactory;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class Frontend implements ExtenderInterface
|
||||
|
@ -43,9 +44,17 @@ class Frontend implements ExtenderInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function route($path, $name, $content = null)
|
||||
{
|
||||
$this->routes[] = compact('path', 'name', 'content');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __invoke(Container $container, Extension $extension = null)
|
||||
{
|
||||
$this->registerAssets($container, $this->getModuleName($extension));
|
||||
$this->registerRoutes($container);
|
||||
}
|
||||
|
||||
private function registerAssets(Container $container, string $moduleName)
|
||||
|
@ -66,6 +75,23 @@ class Frontend implements ExtenderInterface
|
|||
);
|
||||
}
|
||||
|
||||
private function registerRoutes(Container $container)
|
||||
{
|
||||
if (empty($this->routes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$routes = $container->make("flarum.$this->frontend.routes");
|
||||
$factory = $container->make(RouteHandlerFactory::class);
|
||||
|
||||
foreach ($this->routes as $route) {
|
||||
$routes->get(
|
||||
$route['path'], $route['name'],
|
||||
$factory->toFrontend($this->frontend, $route['content'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function getModuleName(?Extension $extension): string
|
||||
{
|
||||
return $extension ? $extension->getId() : 'site-custom';
|
||||
|
|
Loading…
Reference in New Issue
Block a user