首页 文章

如何在Symfony中正确查找,监视和处理已弃用的方法调用?

提问于
浏览
0

我刚刚将Symfony 2.7项目更新为2.8 . 现在我准备将项目更新到Symfony 3.该配置文件显示,每个请求都使用了大量(超过1500个)已弃用的方法/类 .

当然我想解决这些问题 . 但据我所知,弃用的代码是由Symfony本身使用的,而不是我自己的代码 .

这是一个例子:

ConfigCache::__toString() is deprecated since version 2.7 and will be removed in 3.0. Use the getPath() method instead. (4 times)

    ConfigCache::__toString() (called from AllowedMethodsRouterLoader.php at line 51)
    AllowedMethodsRouterLoader::getAllowedMethods() (called from AllowedMethodsRouterLoader.php at line 51)
    AllowedMethodsRouterLoader::getAllowedMethods() (called from AllowedMethodsListener.php at line 41)
    AllowedMethodsListener::onKernelResponse()
    call_user_func() (called from WrappedListener.php at line 61)
    WrappedListener::__invoke()
    call_user_func() (called from EventDispatcher.php at line 184)

    ...a lot more Twig calls...

    Twig_Template::displayWithErrorHandling() (called from Template.php at line 347)
    Twig_Template::display() (called from Template.php at line 358)
    Twig_Template::render() (called from TwigEngine.php at line 50)
    TwigEngine::render() (called from TwigEngine.php at line 72)
    TwigEngine::render() (called from TwigEngine.php at line 97)
    TwigEngine::renderResponse() (called from Controller.php at line 185)
    Controller::render() (called from RegistrationController.php at line 71)

    RegistrationController::registerAction()

    call_user_func_array() (called from HttpKernel.php at line 144)
    HttpKernel::handleRaw() (called from HttpKernel.php at line 64)
    HttpKernel::handle() (called from ContainerAwareHttpKernel.php at line 69)
    ContainerAwareHttpKernel::handle() (called from Kernel.php at line 185)
    Kernel::handle() (called from app_dev.php at line 37)

当然我自己的代码也涉及这个调用堆栈: RegistrationController 处理了请求并使用 Twig 模板来呈现页面 . 但是,使用不推荐使用的 ConfigCache::__toString() 方法的代码来自 AllowedMethodsRouterLoader 类,它是Symfony的一部分 .

Is there anything my code can do to avoid this deprecated code?

我很惊讶,Symfony代码本身使用了弃用的代码 . 有没有办法过滤掉这些消息,只收到我自己代码中的弃用通知?

2 回答

  • 1

    您可能对Sensio Labs(Symfony的创建者)的Deprecation Detector感兴趣 .

    Deprecation Detector on Github

    我在2.8准备移动到3.0时使用了相当多的删除不推荐的类/方法 . 是一个很好的节省时间 . 强烈推荐 .

    我还建议Symfony Upgrade Fixer以节省更多时间,特别是关于表单类 .

  • 1

    它正在运行已弃用的代码 - 在Symfony代码库中,但它是从Twig调用的 . 由于Twig是Symfony的一流部分,但不是Symfony项目的正式部分,因此它拥有自己的版本 . 更新的Twig版本以及其他库将删除已弃用代码的使用,或者至少为改善状态做了一些工作 .

    因此,更新基于Symfony框架的项目的很大一部分也在更新其他正在使用的库 . 只更新composer.json中的 "symfony/symfony" 行是不够的 .

相关问题