@@ -162,7 +162,7 @@ $router->define('CUSTOM', '/', function () {
162162$router->dispatch();
163163``` 
164164
165- If you don't want to  care about HTTP verbs, you can use the ` any() `  method.
165+ If you don't care about HTTP verbs, you can use the ` any() `  method.
166166
167167``` php 
168168use MiladRahimi\PhpRouter\Router;
@@ -225,7 +225,7 @@ $router->dispatch();
225225
226226A URL might have one or more variable parts like product IDs on a shopping website.
227227We call it a route parameter.
228- You can catch them by controller arguments like the example below.
228+ You can catch them by controller method  arguments like the example below.
229229
230230``` php 
231231use MiladRahimi\PhpRouter\Router;
@@ -256,6 +256,8 @@ $router->get('/post/{pid}/comment/{cid}', function ($pid, $cid) {
256256$router->dispatch();
257257``` 
258258
259+ #### Route Parameter Patterns  
260+ 
259261In default, route parameters can have any value, but you can define regex patterns to limit them.
260262
261263``` php 
@@ -291,16 +293,17 @@ use Laminas\Diactoros\Response\JsonResponse;
291293
292294$router = Router::create();
293295
294- $router->get('/test ', function (ServerRequest $request) {
295-     return new JsonResponse( [
296+ $router->get('/', function (ServerRequest $request) {
297+     $info =  [
296298        'method' => $request->getMethod(),
297299        'uri' => $request->getUri()->getPath(),
298300        'body' => $request->getBody()->getContents(),
299301        'parsedBody' => $request->getParsedBody(),
300302        'headers' => $request->getHeaders(),
301303        'queryParameters' => $request->getQueryParams(),
302304        'attributes' => $request->getAttributes(),
303-     ]);
305+     ];
306+     // ...
304307});
305308
306309$router->dispatch();
@@ -409,8 +412,8 @@ class AuthMiddleware
409412{
410413    public function handle(ServerRequestInterface $request, Closure $next)
411414    {
412-         if ($request->getHeader('Authorization')) {
413-             // Check  the auth header... 
415+         if ($request->getHeader('Authorization')) {             
416+             // Call  the next middleware/controller 
414417            return $next($request);
415418        }
416419
@@ -423,7 +426,7 @@ $router = Router::create();
423426// The middleware attribute takes an array of middleware, not a single one!
424427$router->group(['middleware' => [AuthMiddleware::class]], function(Router $router) {
425428    $router->get('/admin', function () {
426-         return 'Admin Panel ';
429+         return 'Admin API ';
427430    });
428431});
429432
@@ -547,12 +550,12 @@ $router->getContainer()->singleton(Database::class, MySQL::class);
547550$router->getContainer()->singleton(Config::class, JsonConfig::class);
548551
549552// Resolve directly
550- $router->get('/direct ', function (Database $database, Config $config) {
553+ $router->get('/', function (Database $database, Config $config) {
551554    // Use MySQL and JsonConfig...
552555});
553556
554557// Resolve container
555- $router->get('/container ', function (Container $container) {
558+ $router->get('/', function (Container $container) {
556559    $database = $container->get(Database::class);
557560    $config = $container->get(Config::class);
558561});
@@ -582,6 +585,7 @@ $router->get('/', function () {
582585try {
583586    $router->dispatch();
584587} catch (RouteNotFoundException $e) {
588+     // It's 404!
585589    $router->getPublisher()->publish(new HtmlResponse('Not found.', 404));
586590} catch (Throwable $e) {
587591    // Log and report...
0 commit comments