mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
[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.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class FindUrlBootManager implements \Pecee\SimpleRouter\IRouterBootManager
|
||||
{
|
||||
protected $result;
|
||||
|
||||
public function __construct(&$result)
|
||||
{
|
||||
$this->result = &$result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
$contact = $router->findRoute('contact');
|
||||
|
||||
if($contact !== null) {
|
||||
$this->result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,11 @@
|
||||
class TestBootManager implements \Pecee\SimpleRouter\IRouterBootManager
|
||||
{
|
||||
|
||||
protected $routes;
|
||||
protected $aliasUrl;
|
||||
protected $rewrite;
|
||||
|
||||
public function __construct(array $routes, string $aliasUrl)
|
||||
public function __construct(array $rewrite)
|
||||
{
|
||||
$this->routes = $routes;
|
||||
$this->aliasUrl = $aliasUrl;
|
||||
$this->rewrite = $rewrite;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,11 +18,11 @@ class TestBootManager implements \Pecee\SimpleRouter\IRouterBootManager
|
||||
*/
|
||||
public function boot(\Pecee\SimpleRouter\Router $router, \Pecee\Http\Request $request): void
|
||||
{
|
||||
foreach ($this->routes as $url) {
|
||||
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($this->aliasUrl);
|
||||
$request->setRewriteUrl($rewrite);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user