You've already forked Php-Template
feat: improve callable handling in JWT and Scope middlewares
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m15s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 1m31s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m39s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m49s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 1m43s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m10s
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m15s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 1m31s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m39s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m49s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 1m43s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m10s
This commit is contained in:
@@ -36,6 +36,11 @@ class JwtMiddleware implements MiddlewareInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface|Dispatcher $handler): ResponseInterface
|
||||
{
|
||||
|
||||
if (!$handler instanceof Dispatcher) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
/** @var Route | null $lastSegment */
|
||||
$lastSegment = array_last($handler->getMiddlewareStack());
|
||||
|
||||
@@ -43,10 +48,19 @@ class JwtMiddleware implements MiddlewareInterface
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
[$class, $method] = $lastSegment->getCallable();
|
||||
$callable = $lastSegment->getCallable();
|
||||
$class = null;
|
||||
$method = null;
|
||||
|
||||
if (class_exists($class::class)) {
|
||||
$reflectionClass = new \ReflectionClass($class::class);
|
||||
if (is_array($callable) && count($callable) === 2) {
|
||||
[$class, $method] = $callable;
|
||||
} elseif (is_string($callable)) {
|
||||
// Handle the case where the callable is a string (e.g., 'ClassName::methodName')
|
||||
[$class, $method] = explode('::', $callable);
|
||||
}
|
||||
|
||||
if (class_exists($class)) {
|
||||
$reflectionClass = new \ReflectionClass($class);
|
||||
|
||||
if ($reflectionClass->hasMethod($method)) {
|
||||
$reflectionMethod = $reflectionClass->getMethod($method);
|
||||
|
||||
@@ -21,6 +21,10 @@ class ScopeMiddleware implements MiddlewareInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface | Dispatcher $handler): ResponseInterface
|
||||
{
|
||||
if (!$handler instanceof Dispatcher) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
/** @var Route | null $lastSegment */
|
||||
$lastSegment = array_last($handler->getMiddlewareStack());
|
||||
|
||||
@@ -28,10 +32,19 @@ class ScopeMiddleware implements MiddlewareInterface
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
[$class, $method] = $lastSegment->getCallable();
|
||||
$callable = $lastSegment->getCallable();
|
||||
$class = null;
|
||||
$method = null;
|
||||
|
||||
if (class_exists($class::class)) {
|
||||
$reflectionClass = new \ReflectionClass($class::class);
|
||||
if (is_array($callable) && count($callable) === 2) {
|
||||
[$class, $method] = $callable;
|
||||
} elseif (is_string($callable)) {
|
||||
// Handle the case where the callable is a string (e.g., 'ClassName::methodName')
|
||||
[$class, $method] = explode('::', $callable);
|
||||
}
|
||||
|
||||
if (class_exists($class)) {
|
||||
$reflectionClass = new \ReflectionClass($class);
|
||||
if ($reflectionClass->hasMethod($method)) {
|
||||
$reflectionMethod = $reflectionClass->getMethod($method);
|
||||
$attributes = $reflectionMethod->getAttributes(Scope::class);
|
||||
|
||||
Reference in New Issue
Block a user