gpt4 book ai didi

php - Symfony 3 - (文件路径)的定义没有类属性并且似乎引用了全局命名空间中的类或接口(interface)

转载 作者:行者123 更新时间:2023-12-04 16:06:26 25 4
gpt4 key购买 nike

有没有人遇到过下面的错误并且知道可能是什么问题?我正在使用异常包为 REST API 输出基于 JSON 的异常消息。

    C:\htdocs\projects\myproject>php bin/console cache:clear --no-warmup
PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition
for "ApiExceptionBundle\Component\Factory\ResponseFactoryInterface" has no class attribute, and appears to
reference a class or interface in the global namespace. Leaving out the "class" attribute is only allowed
for namespaced classes. Please specify the class attribute explicitly to get rid of this error. in C:\htdoc
s\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitio
nValidityPass.php:52
Stack trace:
#0 C:\htdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\Com
piler.php(143): Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass->process(Object(
Symfony\Component\DependencyInjection\ContainerBuilder))
#1 C:\htdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ContainerBui
lder.php(731): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Symfony\ in C:\htdoc
s\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitio
nValidityPass.php on line 52

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition for
"ApiExceptionBundle\Component\Factory\ResponseFactoryInterface" has no class attribute, and appears to refe
rence a class or interface in the global namespace. Leaving out the "class" attribute is only allowed for n
amespaced classes. Please specify the class attribute explicitly to get rid of this error. in C:\htdocs\pro
jects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitionVali
dityPass.php on line 52

Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition for "ApiExceptionBundle\Co
mponent\Factory\ResponseFactoryInterface" has no class attribute, and appears to reference a class or inter
face in the global namespace. Leaving out the "class" attribute is only allowed for namespaced classes. Ple
ase specify the class attribute explicitly to get rid of this error. in C:\htdocs\projects\myproject\vendor\s
ymfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass.php on line 5
2

Call Stack:
4.6333 13914032 1. Symfony\Component\Debug\ErrorHandler->handleException() C:\htdocs\projects\alire
st\vendor\symfony\symfony\src\Symfony\Component\Debug\ErrorHandler.php:0

C:\htdocs\projects\myproject>

这是它引用的文件:

<?php

namespace ApiExceptionBundle\Component\Factory;

use ApiExceptionBundle\Component\Api\ApiProblemInterface;

interface ResponseFactoryInterface
{
public function createResponse(ApiProblemInterface $apiProblem);
}

最佳答案

都是here in the doc

类型提示 (ApiExceptionBundle\Component\Api\ApiProblemInterface) 与服务的 ID 不匹配 (ApiExceptionBundle\Component\Api\ApiProblem ?)。这意味着不能 Autowiring 参数。

你应该添加一个别名

services:
ApiExceptionBundle\Component\Api\ApiProblemInterface: '@ApiExceptionBundle\Component\Api\ApiProblem'

关于php - Symfony 3 - (文件路径)的定义没有类属性并且似乎引用了全局命名空间中的类或接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48567624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com