Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit a89e20b

Browse files
authored
Merge pull request #3 from MrF0o/development
Development
2 parents 5f01480 + 7c5ef34 commit a89e20b

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# php-router
2-
3-
(WORK IN PROGRESS)
4-
52
This router is designed to help you easily and efficiently handle HTTP requests and responses in your PHP applications. It is inspired by the popular Laravel framework, and aims to provide a similar experience and functionality.
63

74
# Getting Started

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"minimum-stability": "dev",
2222
"require": {
23-
"php": ">=7.4"
23+
"php": ">=8.0"
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit": "9.6.x-dev"

src/Router.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static function init()
6464
public static function run()
6565
{
6666
self::init();
67-
$user_uri = $_SERVER['REQUEST_URI'];
67+
$user_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
6868
$user_method = $_SERVER['REQUEST_METHOD'];
6969
$route = self::$routeList->search(new URI($user_uri));
7070

@@ -119,20 +119,27 @@ private function performTests($route, $uri, $user_method)
119119

120120
public static function group(array $options, $callback): void
121121
{
122+
self::init();
122123
self::$isTrackingGroup = true;
123124

124-
if (isset($options['prefix'])) {
125-
$_p = $options['prefix'];
126-
call_user_func($callback);
125+
if ($options && count($options) > 0) {
126+
$_p = $options['prefix'] ?? false;
127+
$_m = $options['middleware'] ?? false;
128+
129+
if ($callback) {
130+
call_user_func($callback);
131+
}
127132

128133
// now $tmpGroup have each grouped route
129-
// 1. apply prefix
130-
self::$tmpGroup->forEach(function (Route $route) use ($_p) {
131-
$route->applyPrefix($_p);
134+
self::$tmpGroup->forEach(function (Route $route) use ($_p, $_m) {
135+
// 1. apply prefix
136+
if ($_p)
137+
$route->applyPrefix($_p);
138+
// 2. apply middlewares
139+
if ($_m)
140+
$route->middleware($_m);
132141
});
133142

134-
// 2. apply middlewares
135-
// TODO
136143
}
137144

138145
self::$routeList->mergeAtTail(self::$tmpGroup);
@@ -205,4 +212,4 @@ public static function generateURL($routeName, ...$params): string
205212
return die("No route with name '$routeName'");
206213
}
207214
}
208-
}
215+
}

0 commit comments

Comments
 (0)