Skip to content

Commit

Permalink
Use rebinding instead of rerouting.
Browse files Browse the repository at this point in the history
  • Loading branch information
miqrogroove committed Dec 5, 2024
1 parent 94c5858 commit 44a0cb6
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace Miqrogroove\Webtrees\FamilyTreeHome;

use Aura\Router\RouterContainer;
use Fisharebest\Webtrees\Http\RequestHandlers\HomePage;
use Fisharebest\Webtrees\Http\RequestHandlers\LoginPage;
use Fisharebest\Webtrees\Module\AbstractModule;
Expand All @@ -41,22 +40,24 @@

public function boot(): void
{
// Get the Webtrees router.
$this->rebind(HomePage::class, TreeHomePage::class);
}

/**
* Dependency injection binding for webtrees
*
* @param string $base Also known as the "abstract" class.
* @param string $custom Also known as the "concrete" class.
*/
private function rebind(string $base, string $custom): void
{
if (version_compare(Webtrees::VERSION, '2.2.0', '>=')) {
$router = Registry::container()->get(RouterContainer::class)->getMap();
$objects = Registry::container();
$objects->set($base, $objects->get($custom));
} else {
$router = app(RouterContainer::class)->getMap();
$objects = app();
$objects->bind($base, $custom);
}

// Retrieve the entire routing table.
$routes = $router->getRoutes();

// Delete the original home page route.
unset($routes[HomePage::class]);
$router->setRoutes($routes);

// Now recreate the home page route and point it to my customized handler.
$router->get(HomePage::class, '/', TreeHomePage::class);
}

/**
Expand Down Expand Up @@ -120,7 +121,7 @@ public function customModuleAuthorName(): string
*/
public function customModuleVersion(): string
{
return '1.0.04';
return '1.0.05';
}

/**
Expand Down

0 comments on commit 44a0cb6

Please sign in to comment.