我对“依赖注入”完全不熟悉,我正在尝试将Symfony Framework的依赖注入组件实现到我的应用程序中 .

我已经按照手册中的描述创建了一个services.yaml . 所以它实际上如下所示:

services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: true
  com\example\myapp\:
    resource: "../php/com/example/myapp"

我的代码:

$container = new ContainerBuilder;

$loader = new YamlFileLoader($container, new FileLocator("/project/path/src/main/resources"));

$loader->load("services.yaml");

$container->get(SomeClass::class);// Throws ReflectionException

每当我尝试从容器中获取服务时,PHP都会抛出一个ReflectionException“类不存在” . 我对组件代码进行了反向设计,并意识到从Definition :: getClass()返回的类始终为null .

我错过了什么吗?