首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决Twig_Function、Twig_Function_Method、Twig_Function_Node等问题

如何解决Twig_Function、Twig_Function_Method、Twig_Function_Node等问题
EN

Stack Overflow用户
提问于 2015-10-06 18:49:53
回答 2查看 17.3K关注 0票数 8

在将symfony从2.3更新到2.7之后,我收到了许多警告消息,但我没有找到解决该问题的链接。

我收到的警告信息是:

代码语言:javascript
复制
DEPRECATED - The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.  -
Called from require() at line 154
Called from DebugClassLoader::loadClass()
Called from spl_autoload_call() at line 25
Called from require() at line 154
Called from DebugClassLoader::loadClass()
Called from spl_autoload_call() at line 22
Called from MenuExtension::getFunctions() at line 1282
Called from Twig_Environment::initExtension() at line 1263
Called from Twig_Environment::initExtensions() at line 1196
Called from Twig_Environment::getUnaryOperators() at line 371
Called from Twig_Lexer::getOperatorRegex() at line 65
Called from Twig_Lexer::__construct() at line 529
Called from Twig_Environment::getLexer() at line 557
Called from Twig_Environment::tokenize() at line 647
Called from Twig_Environment::compileSource() at line 382
Called from Twig_Environment::loadTemplate() at line 126
Called from TwigEngine::load() at line 50
Called from TwigEngine::render() at line 72
Called from TwigEngine::render() at line 97
Called from TwigEngine::renderResponse() at line 176
Called from Controller::render() at line 65
Called from DefaultController::indexAction()
Called from call_user_func_array() at line 3109
Called from HttpKernel::handleRaw() at line 3071
Called from HttpKernel::handle() at line 3222
Called from ContainerAwareHttpKernel::handle() at line 2444
Called from Kernel::handle() at line 34

请注意,这是我使用的twig版本:

代码语言:javascript
复制
php  composer.phar show -i | grep twig
twig/extensions                      v1.0.1             Common additional features for Twig that do not directly belong in core
twig/twig                            v1.22.1            Twig, the flexible, fast, and secure template language for PHP

在我看来,NB.是因为我安装的一些包使用了一些不推荐的函数。因此,下面是composer.json文件,以防它有帮助。

代码语言:javascript
复制
"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.7.*",
    "doctrine/orm": "~2.2,>=2.2.3,<2.5",
    "doctrine/dbal": "<2.5",
    "doctrine/doctrine-bundle": "~1.4",

    "twig/extensions": "1.0.*",

    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",

    "sensio/distribution-bundle": "~3.0,>=3.0.12",
    "sensio/framework-extra-bundle": "~3.0,>=3.0.2",

    "incenteev/composer-parameter-handler": "~2.0",

    "friendsofsymfony/user-bundle": "v2.0.0-alpha3",
    "lunetics/locale-bundle": "v2.4.2",
    "stof/doctrine-extensions-bundle": "1.2.*@dev",
    "knplabs/knp-menu": "2.0.*@dev",
    "knplabs/knp-menu-bundle": "2.0.*@dev",
    "coresphere/console-bundle": "0.3.0",
    "knplabs/knp-markdown-bundle": "1.4.*@dev",
    "lunetics/timezone-bundle": "dev-master",
    "knplabs/knp-time-bundle": "1.4.0",
    "a2lix/translation-form-bundle": "1.*@dev",
    "knplabs/doctrine-behaviors": "1.2.*@dev",
    "genemu/form-bundle": "2.2.*@dev",
    "friendsofsymfony/jsrouting-bundle": "@stable",
    "willdurand/geocoder": "@stable",
    "misd/guzzle-bundle": "1.1.*@dev",
    "friendsofsymfony/rest-bundle": "1.4.*@dev",
    "jms/serializer-bundle": "0.13.*@dev",
    "imagine/imagine": "0.5.*@dev",
    "liip/imagine-bundle": "1.0.*@dev",
    "nelmio/api-doc-bundle": "@stable",
    "hwi/oauth-bundle": "0.4.*@dev",
    "friendsofsymfony/facebook-bundle": "dev-master",
    "willdurand/geocoder-bundle": "3.0.*@dev",
    "google/apiclient": "1.0.*@dev",
    "vich/uploader-bundle": "0.10.0",
    "nomaya/social-bundle": "1.0.*@dev",
    "jms/i18n-routing-bundle": "dev-master"
}

NB.我有类似的警告消息给Twig_Function_MethodTwig_Function_Node,.

NB. --这个链接告诉我们有些贬义,但没有具体说明如何解决它们。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-09 13:59:06

我发现这些包引起了我的不满。要找到它们,只需查看包含单词Twig_Function_Method的文件(例如,通过以下命令):

代码语言:javascript
复制
grep --exclude-dir={'./app/cache/','./app/logs/'} -rnw '.' -e "Twig_Filter_Method"

其结果是:

代码语言:javascript
复制
./vendor/jms/translation-bundle/JMS/TranslationBundle/Twig/TranslationExtension.php:56:            'desc' => new \Twig_Filter_Method($this, 'desc'),
./vendor/jms/translation-bundle/JMS/TranslationBundle/Twig/TranslationExtension.php:57:            'meaning' => new \Twig_Filter_Method($this, 'meaning'),
./vendor/jms/serializer/src/JMS/Serializer/Twig/SerializerExtension.php:46:            'serialize'      => new \Twig_Filter_Method($this, 'serialize'),
./vendor/nelmio/api-doc-bundle/Nelmio/ApiDocBundle/Twig/Extension/MarkdownExtension.php:22:            'extra_markdown' => new \Twig_Filter_Method($this, 'markdown', array('is_safe' => array('html'))),
./vendor/knplabs/knp-time-bundle/Knp/Bundle/TimeBundle/Twig/Extension/TimeExtension.php:46:            'ago' => new \Twig_Filter_Method($this, 'diff', array(
./vendor/twig/twig/doc/deprecated.rst:45:  * ``Twig_Filter_Method``
./vendor/twig/twig/doc/advanced_legacy.rst:707:You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function``
./vendor/twig/twig/doc/advanced_legacy.rst:715:                'rot13' => new Twig_Filter_Method($this, 'rot13Filter'),
./vendor/twig/twig/doc/advanced_legacy.rst:727:The first argument of the ``Twig_Filter_Method`` constructor is always
./vendor/twig/twig/doc/advanced_legacy.rst:747:                'date' => new Twig_Filter_Method($this, 'dateFilter'),
./vendor/twig/twig/lib/Twig/Filter/Method.php:12:@trigger_error('The Twig_Filter_Method class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.', E_USER_DEPRECATED);
./vendor/twig/twig/lib/Twig/Filter/Method.php:23:class Twig_Filter_Method extends Twig_Filter

最后,这些是引起我反感的包:jms/translation-bundlenelmio/api-doc-bundleknplabs/knp-time-bundle

我将等待这些包得到更新。

我希望答案是帮助别人。

票数 14
EN

Stack Overflow用户

发布于 2017-04-19 12:16:54

我找到这个线程是因为我在更新树枝时遇到了同样的问题。

在日志中,您可以找到这一行:

代码语言:javascript
复制
/logs/symfony/dev.log:7000:[2017-04-05 10:10:57] php.INFO: The Twig_Function_Node class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.

也许这会对下一个到达这里的人有所帮助。

只需替换:

代码语言:javascript
复制
'form_range' => new \Twig_Function_Node(...);

通过以下方式:

代码语言:javascript
复制
'form_range' => new \Twig_SimpleFunction(...),
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32977456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档