Files
simple-php-router/tests/Pecee/SimpleRouter/Dummy/Managers/TestBootManager.php
Simon Sessingø 801f1e68cc [BUGFIX] BootManager findRoute not working.
- Fixed findRoute not working in BootManager as reported by issue: #448
- Added more comprehensive php-unit tests for bootmanagers including findUrl.
2021-03-22 18:05:27 +01:00

30 lines
750 B
PHP

<?php
class TestBootManager implements \Pecee\SimpleRouter\IRouterBootManager
{
protected $rewrite;
public function __construct(array $rewrite)
{
$this->rewrite = $rewrite;
}
/**
* Called when router loads it's routes
*
* @param \Pecee\SimpleRouter\Router $router
* @param \Pecee\Http\Request $request
*/
public function boot(\Pecee\SimpleRouter\Router $router, \Pecee\Http\Request $request): void
{
foreach ($this->rewrite as $url => $rewrite) {
// If the current url matches the rewrite url, we use our custom route
if ($request->getUrl()->contains($url) === true) {
$request->setRewriteUrl($rewrite);
}
}
}
}