Skip to content

Commit

Permalink
change RegexRoute signature&logic, create MatchPathRoute (fix #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisGalliano committed Apr 25, 2019
1 parent 33aff80 commit e98cf5e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "chrisgalliano/pion",
"version": "1.0.0",
"description": "Light PHP Framework",
"minimum-stability": "dev",
"license": "MIT",
Expand Down
17 changes: 17 additions & 0 deletions src/Routing/Route/MatchPathRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?

declare(strict_types=1);

namespace Pion\Routing\Route;

class MatchPathRoute extends RegexRoute
{
public function __construct(string $path, string $actionClass)
{
parent::__construct(
$path,
$actionClass,
'!^' . preg_quote($path, '!') . '$!'
);
}
}
13 changes: 8 additions & 5 deletions src/Routing/Route/RegexRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ class RegexRoute implements RouteInterface
*/
private $actionClass;

public function __construct(string $path, string $actionClass)
/**
* @var string
*/
private $pattern;

public function __construct(string $path, string $actionClass, string $pattern)
{
$this->path = $path;
$this->actionClass = $actionClass;
$this->pattern = $pattern;
}

public function path(): string
Expand All @@ -30,10 +36,7 @@ public function path(): string

public function isSupported(RequestInterface $request): bool
{
return (bool)preg_match(
'!^' . preg_quote($this->path, '!') . '$!',
$request->uri()->getPath()
);
return (bool)preg_match($this->pattern, $request->uri()->getPath());
}

public function actionClass(): string
Expand Down

0 comments on commit e98cf5e

Please sign in to comment.