弃用Symfony解决方案

4
如何解决在升级 Symfony 到 4.4 版本后遇到的问题。
[2020-01-03 08:46:27] php.INFO: User Deprecated: The "twig.exception_listener" service is deprecated since Symfony 4.4. {"exception":"[object] (ErrorException(code: 0): User Deprecated: The \"twig.exception_listener\" service is deprecated since Symfony 4.4. at /var/www/api/var/cache/prod/Container8sfHI7P/getTwig_ExceptionListenerService.php:9)"} []
[2020-01-03 08:46:27] php.INFO: User Deprecated: The "Symfony\Component\HttpKernel\EventListener\ExceptionListener" class is deprecated since Symfony 4.4, use "ErrorListener" instead. {"exception":"[object] (ErrorException(code: 0): User Deprecated: The \"Symfony\\Component\\HttpKernel\\EventListener\\ExceptionListener\" class is deprecated since Symfony 4.4, use \"ErrorListener\" instead. at /var/www/api/vendor/symfony/http-kernel/EventListener/ExceptionListener.php:25)"} []
[2020-01-02 05:28:12] php.INFO: User Deprecated: Auto-injection of the container for "\App\Controller\InstallController" is deprecated since Symfony 4.2. Configure it as a service instead. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Auto-injection of the container for \"\\App\\Controller\\InstallController\" is deprecated since Symfony 4.2. Configure it as a service instead. at /var/www/api/vendor/symfony/framework-bundle/Controller/ControllerResolver.php:64)"} []

废弃并不是你立刻面临的问题,它只是表示某个功能将来会被移除。因此,你不需要立即修复它,但你需要制定计划,改变你的代码,并在应用程序的未来版本中停止使用这些功能。你展示的这些消息中至少有两条给出了你应该使用什么替代方案的指示,所以对于这些情况,你应该已经有一些解决方法的想法了。 - ADyson
例如第二条消息中使用了供应商文件,我该如何解决它,因为它是供应商文件而不是版本控制文件。 - Mikel
1
嗯,我猜你的代码中某处正在使用“ExceptionListener”类?如果是这样,你必须停止使用它。如果是一些供应商代码在使用它,那么你必须等待供应商的更新。或者你可以去检查他们是否已经发布了更新。但是像我说的,这只是一个警告...目前并没有实际问题。你的代码现在不会出现任何问题...只有在将来的版本中最终从代码中删除这些类,并且你没有做出任何更改以停止在其他地方使用它们时才会出现问题。 - ADyson
1个回答

6
我也觉得这个问题有些棘手。它不会在composer更新时自动解决,因为它是配置的一部分,并且只有在第一次要求包时才从其recipe应用。

您需要更改三个与4.4默认配置中更改的内容相同的内容(我在下面使用点表示嵌套密钥):

  • config/packages/twig.yaml中添加twig.exception_controller: null
  • config/routes/dev/twig.yaml中将_errors.resource更改为@FrameworkBundle/Resources/config/routing/errors.xml
  • config/routes/dev/twig.yaml重命名为config/routes/dev/framework.yaml

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接