Skip to content

Commit

Permalink
Allow Overriding frontend routes
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Feb 4, 2021
1 parent 161cd66 commit 2359a46
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Extend/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Frontend implements ExtenderInterface
private $css = [];
private $js;
private $routes = [];
private $removedRoutes = [];
private $content = [];

public function __construct(string $frontend)
Expand Down Expand Up @@ -59,6 +60,13 @@ public function route(string $path, string $name, $content = null)
return $this;
}

public function removeRoute(string $name)
{
$this->removedRoutes[] = compact('name');

return $this;
}

/**
* @param callable|string $callback
* @return $this
Expand Down Expand Up @@ -141,7 +149,7 @@ function (Saved $event) use ($container, $abstract) {

private function registerRoutes(Container $container)
{
if (empty($this->routes)) {
if (empty($this->routes) && empty($this->removedRoutes)) {
return;
}

Expand All @@ -151,6 +159,10 @@ function (RouteCollection $collection, Container $container) {
/** @var RouteHandlerFactory $factory */
$factory = $container->make(RouteHandlerFactory::class);

foreach ($this->removedRoutes as $route) {
$collection->removeRoute('GET', $route['name']);
}

foreach ($this->routes as $route) {
$collection->get(
$route['path'],
Expand Down

0 comments on commit 2359a46

Please sign in to comment.