Skip to content

Commit 8896484

Browse files
committedJun 20, 2023
change route
1 parent 776d23c commit 8896484

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed
 

‎AmazePHP/src/Router.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
namespace AmazePHP;
4+
35
use Illuminate\Container\Container;
46

57
class Router
@@ -10,6 +12,7 @@ class Router
1012
private $routeCount = 0;
1113
protected static $_nameList = [];
1214
private $_path = [];
15+
private $container;
1316

1417
public function __construct()
1518
{
@@ -81,20 +84,24 @@ public function doRouting()
8184
preg_match_all("/{[a-zA-Z0-9\_\-}]+/", $route['url'], $matches1);
8285

8386
foreach ($matches1[0] as $key => $value) {
84-
$matches[trim($value,"{}")]= $matches[$key] ?? null;
87+
$matches[trim($value, "{}")]= $matches[$key] ?? null;
8588
}
8689

8790
foreach ($matches as $mkey => &$mvalue) {
91+
$mvalue =trim((string)$mvalue, "/");
8892

89-
$mvalue =trim( (string)$mvalue,"/");
90-
91-
if (is_null($mvalue ) || empty($mvalue) ){
93+
if (is_null($mvalue) || empty($mvalue)) {
9294
unset($matches[$mkey]);
9395
}
9496
}
9597

96-
// echo call_user_func_array($route['callback'], $matches);
97-
echo $this->container->call($route['callback'], $matches);
98+
if ($route['callback'] instanceof \Closure) {
99+
echo $this->container->call($route['callback'], $matches);
100+
} else {
101+
$controller= $this->container->make($route['callback'][0]);
102+
// echo call_user_func_array($route['callback'], $matches);
103+
echo $this->container->call([$controller, $route['callback'][1]], $matches);
104+
}
98105
});
99106
} else {
100107
$is_match++;
@@ -139,9 +146,3 @@ public function name($name)
139146
return $this;
140147
}
141148
}
142-
143-
144-
//autoload
145-
// spl_autoload_register(function ($class_name) {
146-
// require_once __DIR__ . '/' . str_replace('\\', '/', $class_name) . '.php';
147-
// });

‎App.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use AmazePHP\Log;
1010

1111
define('BASE_PATH', __DIR__);
12-
define('APP_VERSION', '2.2.2');
12+
define('APP_VERSION', '2.3.0');
1313
include 'AmazePHP/src/DotEnv.php';
1414
include 'AmazePHP/src/ErrorHandel.php';
1515
(new AmazePHP\DotEnv());

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ see config/route.php
117117
[
118118
['GET'],
119119
'/',
120-
[new App\Index, 'index'],
120+
[App\Controllers\Index::class, 'index'],
121121
['routename'],
122122
'middleware'=>[App\Middleware\a2Middleware::class,App\Middleware\b2Middleware::class],
123123
],

‎config/route.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[
66
['GET'],
77
'/',
8-
[new App\Controllers\Index, 'index'],
8+
[App\Controllers\Index::class, 'index'],
99
'nameroute1'//name route (optional)
1010
],
1111

0 commit comments

Comments
 (0)
Failed to load comments.