我的控制器看起来像:
use Psr\Http\Message\ServerRequestInterface;
class HelloController extends AbstractController
{
public function __invoke(ServerRequestInterface $request): Response
{
dd($request)
return $this->json([]);
}
转到此控制器的 URL 后,我收到以下错误:
Cannot autowire argument $request of "HelloController()": it references interface "Psr\Http\Message\ServerRequestInterface" but no such service exists. Did you create a class that implements this interface?
我的 composer.json 看起来像:
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.4",
"nyholm/psr7": "^1.1",
"psr/http-client": "^1.0",
"sensio/framework-extra-bundle": "^6.1",
"symfony/asset": "^4.1",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.1",
"symfony/messenger": "^4.1",
"symfony/psr-http-message-bridge": "^1.0",
"symfony/security-bundle": "^4.1",
"symfony/yaml": "^4.1",
"php-http/httplug": "^2.0",
"php-http/guzzle6-adapter": "^2.0",
"guzzlehttp/psr7": "^1.5"
},
我没有在services.yaml
文件中设置任何内容。