我想在我的web應用程序中有一個服務和類名的列表。我可以在控制檯使用這個命令:如何在Symfony中以編程方式獲得服務列表?
php bin/console debug:container
我得到這樣的:
Symfony Container Public Services
=================================
-------------------------------------------------------------------- --------------------------------------------------------------------------------------------
Service ID Class name
-------------------------------------------------------------------- --------------------------------------------------------------------------------------------
annotation_reader Doctrine\Common\Annotations\CachedReader
app.annotations.softdelete.driver AppBundle\Doctrine\SoftDelete\Mapping\Driver\Annotation
app.annotations.translate.driver AppBundle\Doctrine\Mapping\Driver\TranslateDriver
app.be_auth_controller.listener AppBundle\EventListener\BeAuthControllerListener
我想有使用的Symfony 3.
我創建了一個網頁上的信息服務,我使用:
返回類似:
[
0 => "service_container"
1 => "annotation_reader"
2 => "annotations.reader"
3 => "app.annotations.softdelete.driver"
4 => "app.annotations.translate.driver"
...
]
我不知道,如何得到類名。
在任何情況下,本工作:
get_class($this->container->get($this->container->getServiceIds()[1]))
但在另一些情況下,它拋出不同的異常。
你有什麼想法嗎?
謝謝。