php 在 Symfony 2(.7) 中禁用已弃用的警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28850809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable deprecated warning in Symfony 2(.7)
提问by Roel Veldhuizen
Since my Symfony 2
update to 2.7
. I get a lot of deprecated erors in PHPUnit
and console
(message is clear by now).
自从我Symfony 2
更新到2.7
. 我在PHPUnit
and 中遇到了很多不推荐使用的错误console
(现在消息已经很清楚了)。
ProjectX\ApiBundle\Tests\Controller\SectionsControllerTest::testPostDebug()
The twig.form.resources configuration key is deprecated since version 2.6 and will be removed in 3.0. Use the twig.form_themes configuration key instead.
Any idea how to disable them for now?
知道如何暂时禁用它们吗?
采纳答案by phpguru
I have the same problem and solved it similar to the below link. Symfony declares to report all errors and overrides what you put in php.ini by design (otherwise it couldn't catch & display nice stack traces for you).
我有同样的问题并解决了类似于下面的链接。Symfony 声明报告所有错误并按设计覆盖您在 php.ini 中放置的内容(否则它无法为您捕获和显示漂亮的堆栈跟踪)。
So, you'll need to override Symfony2's built-in error reporting by creating an init()
function in your AppKernel.php and setting the error_reporting how you'd like there, along with (probably) some environment detection to make sure you don't display errors in production, for example:
因此,您需要通过init()
在 AppKernel.php 中创建一个函数并设置 error_reporting 的方式来覆盖 Symfony2 的内置错误报告,以及(可能)一些环境检测以确保您不显示生产中的错误,例如:
// Add this to app/AppKernel.php
public function init()
{
if ($this->debug) {
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
} else {
ini_set('display_errors', 0);
}
}
More details here (use Google Translate if you do not read Russian :) http://tokarchuk.ru/2012/12/disable-deprecated-warnings-in-symfony-2/
此处有更多详细信息(如果您不会阅读俄语,请使用谷歌翻译 :) http://tokarchuk.ru/2012/12/disable-deprecated-warnings-in-symfony-2/
回答by James Grundner
AppKernel's inherited Kernel::init() function is depreciated itself so changing it is not a viable long term solution.
AppKernel 继承的 Kernel::init() 函数本身已贬值,因此更改它不是一个可行的长期解决方案。
You can easily override the error reporting by changing the call to Debug::enable(); in both app/console and web/app_dev.php like so.
您可以通过更改对 Debug::enable(); 的调用轻松覆盖错误报告。在 app/console 和 web/app_dev.php 中都是这样。
Change
改变
Debug::enable();
to
到
Debug::enable(E_RECOVERABLE_ERROR & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED, false);
This will leave all other error reporting in tact while suppressing depreciated warnings. And you don't need to mess with the Kernel at all.
这将保留所有其他错误报告,同时抑制折旧警告。而且您根本不需要弄乱内核。
回答by j-guyon
In my case, i couldn't hide deprecated warning without using SYMFONY_DEPRECATIONS_HELPER
environnment variable.
就我而言,我无法在不使用SYMFONY_DEPRECATIONS_HELPER
环境变量的情况下隐藏已弃用的警告。
Change your phpunit.xml
with
改变你phpunit.xml
的
<phpunit>
<!-- ... -->
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>
</phpunit>
Then, you'll just have one message like "Remaining deprecation notices (x)" which is not considered as a test failure.
然后,您只会收到一条消息,例如“剩余弃用通知 (x)”,这不会被视为测试失败。
Hope this will help.
希望这会有所帮助。
回答by Dimosthenis Nikoudis
Note that disabling deprecation warnings via error_reporting() or Debug::enable() will not prevent them from being logged to dev.log. To disable them from being logged you'll need to change the log level in your monolog handler to "warning" (deprecation warnings are logged as "info" in the "php" channel).
请注意,通过 error_reporting() 或 Debug::enable() 禁用弃用警告不会阻止它们被记录到 dev.log。要禁止它们被记录,您需要将 Monolog 处理程序中的日志级别更改为“警告”(弃用警告在“php”频道中记录为“信息”)。
Alternatively, to prevent other logs from being affected, you can create a separate monolog handler with a different level for the "php" channel e.g.
或者,为了防止其他日志受到影响,您可以为“php”通道创建一个具有不同级别的单独的 Monolog 处理程序,例如
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
formatter: monolog.formatter.session_request
channels: '!php'
php:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: warning
formatter: monolog.formatter.session_request
channels: 'php'
回答by axelvnk
The twig.form configuration key has been removed in the new version of Twig. Therefore you should replace the key in your config.yml
twig.form 配置键已在新版本的 Twig 中删除。因此,您应该替换 config.yml 中的密钥
///DEPRECATED :
twig:
form:
resources:
- 'path_to_template_file'
// NEW WAY :
twig:
form_themes:
- 'path_to_template_file'