我想自动将AppBundle / Service目录中的所有类添加为单独的服务。有一些样板代码,加上Symfony的安装应该做到这一点:
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
AppBundle\:
resource: '../../src/AppBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
问题是即使我在Service
目录中创建了一个类,我也无法在debug:container
中找到它作为服务。使用以下命令添加此服务没有问题:
app.my_service:
class: AppBundle\Service\MyService
但是如何自动添加服务,而无需单独添加服务?