-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Hi. The #[Controller] and #[Middleware] annotations don't work with the __invoke method in invokable controllers.
This doesn't work:
<?php
declare(strict_types=1);
namespace App\Controllers;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Middleware\RestrictToLocalhost;
#[Controller]
class HealthCheckController
{
#[RequestMapping(path: "/health", methods: "get")]
#[Middleware(RestrictToLocalhost::class)]
public function __invoke(): array
{
return [
'status' => 'ok',
'timestamp' => time(),
];
}
}This works correctly:
<?php
declare(strict_types=1);
namespace App\Controllers;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Middleware\RestrictToLocalhost;
#[Controller]
class HealthCheckController
{
#[RequestMapping(path: "/health", methods: "get")]
#[Middleware(RestrictToLocalhost::class)]
public function check(): array
{
return [
'status' => 'ok',
'timestamp' => time(),
];
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working