我刚刚更新了一个Symfony 2.7项目到2.8。现在我准备将该项目更新为Symfony 3.该配置文件显示,每个请求都使用了大量(超过1500个)不推荐使用的方法/类。如何在Symfony中正确查找,监视和处理不建议使用的方法调用?
当然我想解决这些问题。但据我所知,不赞成使用的代码是由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的一部分。
有没有什么我的代码可以做,以避免这个弃用的代码?
我很惊讶,Symfony代码本身使用不推荐使用的代码。有没有什么方法可以过滤掉这些消息,并只在自己的代码中得到关于弃用的通知?
这只是意味着Sensio实验室已经在2.8代码中将某些代码片段标记为版本3已弃用。这些通知和实际上勤奋的标记是很正常的。它可以让你知道在做这个3.x升级之前会发生什么。任何在symfony核心中被标记为不推荐使用的代码都会针对版本3进行更新,因此您不必担心这些代码。 –
“不建议使用”的提示意味着,某段代码*仍可以被使用,但它不应该被使用,因为它将在下一个版本中被删除。在版本3更新之后使用这样的代码会破坏代码。因此,应该检查一些**自己的**代码并删除不推荐使用的代码。但是:它不是我的代码,它使用不赞成的部分,而是使用Symfony代码本身。我必须对此做任何事吗? –
不,你不知道。我很清楚贬值的含义。但谢谢你的解释。在转换到Symfony3之前,基本上修改*您的*代码。他们将更新他们的核心。这是他们让你知道发生了什么的方式。以这种方式思考它......当他们构建第3版时,他们正在将2.8中的任何代码标记为“已弃用”,这样当人们使用2.8时,他们会明白变化的方面当他们移动到3。这是完全正常的。不要编辑核心代码。 –