Skip to content

Commit

Permalink
Merge pull request #18 from bim-g/dev
Browse files Browse the repository at this point in the history
[ENH] Add middleware support to groupe routing
  • Loading branch information
bim-g authored Apr 5, 2023
2 parents ad8e2b0 + fbe4820 commit da85d29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function __construct(string $path, $callable,$middleware = null)
* @param string|null $url
* @return bool
*/
function match(?string $url): bool
public function match(?string $url): bool
{
$url = trim($url, '/');
$path = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], $this->_path);
Expand All @@ -56,7 +56,7 @@ function match(?string $url): bool
/**
*
*/
function call()
public function call()
{
try {
if (count($this->middleware_tab) > 0) {
Expand Down Expand Up @@ -90,7 +90,7 @@ private function paramMatch(array $match): string
* @param $regex
* @return $this
*/
function with($param, $regex): Route
public function with($param, $regex): Route
{
$this->_params[$param] = str_replace('(', '(?:', $regex);
return $this;
Expand All @@ -99,7 +99,7 @@ function with($param, $regex): Route
/**
* @return array
*/
function getmatch(): array
public function getmatch(): array
{
return $this->_matches;
}
Expand All @@ -108,7 +108,7 @@ function getmatch(): array
* @param $params
* @return array|string|string[]
*/
function getUrl($params)
public function getUrl($params)
{
$path = $this->_path;
foreach ($params as $k => $v) {
Expand All @@ -121,7 +121,7 @@ function getUrl($params)
* @param $middleware
* @return $this
*/
function middleware($middleware): Route
public function middleware($middleware): Route
{
$this->middleware_tab[] = $middleware;
return $this;
Expand Down
15 changes: 8 additions & 7 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function __construct()
* @param string|null $name
* @return Route
*/
function get(string $path, $callable, ?string $name = null): Route
public function get(string $path, $callable, ?string $name = null): Route
{
return $this->add($path, $callable, 'GET', $name);
}
Expand All @@ -48,7 +48,7 @@ function get(string $path, $callable, ?string $name = null): Route
* @param string|null $name
* @return Route
*/
function post(string $path, $callable, ?string $name = null): Route
public function post(string $path, $callable, ?string $name = null): Route
{
return $this->add($path, $callable, 'POST', $name);
}
Expand All @@ -60,7 +60,7 @@ function post(string $path, $callable, ?string $name = null): Route
* @param string|null $name
* @return Route
*/
function delete(string $path, $callable, ?string $name = null): Route
public function delete(string $path, $callable, ?string $name = null): Route
{
return $this->add($path, $callable, 'DELETE', $name);
}
Expand All @@ -72,7 +72,7 @@ function delete(string $path, $callable, ?string $name = null): Route
* @param string|null $name
* @return Route
*/
function put(string $path, $callable, ?string $name = null): Route
public function put(string $path, $callable, ?string $name = null): Route
{
return $this->add($path, $callable, 'PUT', $name);
}
Expand All @@ -81,7 +81,7 @@ function put(string $path, $callable, ?string $name = null): Route
* @param $base_route
* @param callable $callable
*/
function group($base_route, callable $callable): void
public function group($base_route, callable $callable): void
{
$pattern = $base_route;
if (is_array($base_route)) {
Expand Down Expand Up @@ -147,7 +147,8 @@ private function add(string $path, $callable, string $method, ?string $name = nu
* @param array $params
* @return void
*/
function url(string $name, array $params = [])
public function url(string $name, array $params = [])

{
try {
if (!isset($this->_nameRoute[$name])) {
Expand Down Expand Up @@ -192,7 +193,7 @@ protected function trigger404($match = null){
/**
* @return void
*/
function run()
public function run()
{
try {
if (!isset($this->routes[$_SERVER['REQUEST_METHOD']])) {
Expand Down

0 comments on commit da85d29

Please sign in to comment.