Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 4 autowire不使用根命名空间_Php_Symfony_Symfony4 - Fatal编程技术网

Php Symfony 4 autowire不使用根命名空间

Php Symfony 4 autowire不使用根命名空间,php,symfony,symfony4,Php,Symfony,Symfony4,在标准中,所有内容都放在App名称空间下。 因此,如果我将有这样的结构,带有TestController具有公共函数xxx(TestInterface$test)一切正常 -src -Core -TestInterface (App\Core) -Api -Controller -TestController (App\Api\Controller) -Domain -Service -TestService implements TestInterface (Ap

在标准中,所有内容都放在
App
名称空间下。 因此,如果我将有这样的结构,带有
TestController
具有
公共函数xxx(TestInterface$test)一切正常

-src
 -Core
  -TestInterface (App\Core)
 -Api
  -Controller
   -TestController (App\Api\Controller)
 -Domain
  -Service
   -TestService implements TestInterface (App\Domain\Service)
现在的问题是我的项目没有
App
前缀。 我的结构如下所示:

-src
 -Core
  -TestInterface (Core)
 -Api
  -Controller
   -TestController (Api\Controller)
 -Domain
  -Service
   -TestService implements TestInterface (Domain\Service)
composer.json

"autoload": {
    "psr-4": {
        "": "src/"
    }
},
服务。yaml

Core\:
    resource: '../src/Core/*'
    exclude: '../src/Core/{Entity,Migrations,Tests,Kernel.php}'

Domain\:
    resource: '../src/Domain/*'
    exclude: '../src/Domain/{Entity,Migrations,Tests,Kernel.php}'

Api\Controller\:
    resource: '../src/Api/Controller'
    tags: ['controller.service_arguments']
最有趣的是,只要我使用直接的类名称空间,几乎所有的事情都可以正常工作,包括依赖项注入。仅通过接口查找不起作用

这是有效的:
公共函数xxx(TestService$test)

这不起作用:
公共函数xxx(TestInterface$test)

错误如下:

无法解析的参数$test “Api\Controller\TestController::xxx()”: 无法自动连线服务“.service\u locator.EcpiaYx”:它引用接口“Core\TestInterface”,但不存在此类服务。 您可能应该将此接口别名为现有的“Domain\TestService”服务


只是经历了同样的问题。有趣的是,容器确切地知道实现该接口的唯一服务,并建议为其创建别名,但不自动连接:-s