This commit is contained in:
2023-04-16 12:44:43 +08:00
parent 218fd19135
commit 9f5afeab54
8 changed files with 118 additions and 41 deletions
+7 -4
View File
@@ -127,17 +127,19 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
}
}
$hashMap->put('handler', $handler);
$this->registerMiddleware($path);
$this->registerMiddleware($handler->getClass(), $handler->getMethod());
}
/**
* @param string $path
* @param string $class
* @param string $method
* @return void
* @throws ReflectionException
* @throws Exception
*/
public function registerMiddleware(string $path): void
public function registerMiddleware(string $class, string $method): void
{
$middlewares = array_column($this->groupTack, 'middleware');
if (count($middlewares) > 0) {
@@ -147,7 +149,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
$middleware = [$middleware];
}
foreach ($middleware as $value) {
$manager->addPathMiddleware($path, $value);
$manager->set($class, $method, $value);
}
}
}
@@ -158,6 +160,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
* @param string $path
* @param string $method
* @return Handler|null
* @throws ReflectionException
*/
public function query(string $path, string $method): ?Handler
{