diff --git a/src/Security/SecurityHandler.php b/src/Security/SecurityHandler.php index b41d182..437cac2 100644 --- a/src/Security/SecurityHandler.php +++ b/src/Security/SecurityHandler.php @@ -14,11 +14,11 @@ class SecurityHandler { protected ResponseInterface $redirectResponse; - protected ? \Closure $unauthorizeResponse; + protected \Closure|ResponseInterface|null $unauthorizeResponse; protected ? Taxus $taxus; - public function __construct(ResponseInterface $redirectResponse, ? \Closure $unauthorizeResponse = null, ? Taxus $taxus = null) { + public function __construct(ResponseInterface $redirectResponse, \Closure|ResponseInterface|null $unauthorizeResponse = null, ? Taxus $taxus = null) { $this->redirectResponse = $redirectResponse; $this->unauthorizeResponse = $unauthorizeResponse; $this->taxus = $taxus; @@ -51,6 +51,10 @@ class SecurityHandler { } if ($this->unauthorizeResponse) { + if ($this->unauthorizeResponse instanceof ResponseInterface) { + return $this->unauthorizeResponse; + } + return call_user_func_array($this->unauthorizeResponse, [ $user, ['method' => $fromMethod, 'object' => $fromObject ], $className, $methodName ]); } else {