【问题标题】:The ability to pass file names to the Symfony\Component\Yaml\Yaml::parse method is deprecated将文件名传递给 Symfony\Component\Yaml\Yaml::parse 方法的功能已被弃用
【发布时间】:2016-06-08 08:01:24
【问题描述】:

我是 Symfony2 的新手,现在已经工作了将近 3 周。
一切进展顺利,但无论使用何种实体,我在每个页面上都有 4 个不推荐使用的警告,需要学说进行交互(映射是通过 yaml 文件完成的)。

将文件名传递给 Symfony\Component\Yaml\Yaml::parse 方法自版本以来已弃用 2.2 并将在 3.0 中删除。而是传递文件的 YAML 内容。 (4次)

我不知道我做错了什么,或者是否有问题我可以修复以消除警告。

感谢您的帮助!

以防万一,这里是完整的堆栈跟踪:

Yaml::parse() (called from YamlDriver.php at line 712)
YamlDriver::loadMappingFile() (called from FileDriver.php at line 115)
FileDriver::getElement() (called from YamlDriver.php at line 55)
YamlDriver::loadMetadataForClass() (called from MappingDriverChain.php at line 102)
MappingDriverChain::loadMetadataForClass() (called from ClassMetadataFactory.php at line 116)
ClassMetadataFactory::doLoadMetadata() (called from AbstractClassMetadataFactory.php at line 332)
AbstractClassMetadataFactory::loadMetadata() (called from AbstractClassMetadataFactory.php at line 216)
AbstractClassMetadataFactory::getMetadataFor() (called from EntityManager.php at line 265)
EntityManager::getClassMetadata() (called from DefaultRepositoryFactory.php at line 67)
DefaultRepositoryFactory::createRepository() (called from DefaultRepositoryFactory.php at line 50)
DefaultRepositoryFactory::getRepository() (called from EntityManager.php at line 665)
EntityManager::getRepository() (called from UserManager.php at line 40)
UserManager::__construct() (called from appDevDebugProjectContainer.php at line 1582)
appDevDebugProjectContainer::getFosUser_UserManagerService() (called from Container.php at line 312)
Container::get() (called from appDevDebugProjectContainer.php at line 3632)
appDevDebugProjectContainer::getFosUser_UserProvider_UsernameService() (called from Container.php at line 312)
Container::get() (called from appDevDebugProjectContainer.php at line 3690)
appDevDebugProjectContainer::getSecurity_Authentication_ManagerService() (called from Container.php at line 312)
Container::get() (called from appDevDebugProjectContainer.php at line 2299)
appDevDebugProjectContainer::getSecurity_Firewall_Map_Context_MainService() (called from Container.php at line 312)
Container::get() (called from classes.php at line 2964)
FirewallMap::getListeners() (called from classes.php at line 2606)
Firewall::onKernelRequest()
call_user_func() (called from WrappedListener.php at line 61)
WrappedListener::__invoke()
call_user_func() (called from classes.php at line 1853)
EventDispatcher::doDispatch() (called from classes.php at line 1771)
EventDispatcher::dispatch() (called from TraceableEventDispatcher.php at line 132)
TraceableEventDispatcher::dispatch() (called from HttpKernel.php at line 120)
HttpKernel::handleRaw() (called from HttpKernel.php at line 62)
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 30)

如果需要,composer.phar show --installed的结果

doctrine/annotations                 v1.2.7  Docblock Annotations Parser
doctrine/cache                       v1.5.4  Caching library offering an object-oriented API for many cache backends
doctrine/collections                 v1.3.0  Collections Abstraction library
doctrine/common                      v2.5.3  Common Library for Doctrine projects
doctrine/dbal                        v2.5.4  Database Abstraction Layer
doctrine/doctrine-bundle             1.6.2   Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       1.3.0   Symfony Bundle for Doctrine Cache
doctrine/inflector                   v1.1.0  Common String Manipulations with regard to casing and singular/plural rules.
doctrine/lexer                       v1.0.1  Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm                         v2.4.8  Object-Relational-Mapper for PHP
friendsofsymfony/user-bundle         v1.3.6  Symfony FOSUserBundle
incenteev/composer-parameter-handler v2.1.2  Composer script handling your ignored parameter file
ircmaxell/password-compat            v1.0.4  A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash
jdorn/sql-formatter                  v1.2.17 a PHP SQL highlighting library
monolog/monolog                      1.17.2  Sends your logs to files, sockets, inboxes, databases and various web services
paragonie/random_compat              v1.2.0  PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
psr/log                              1.0.0   Common interface for logging libraries
sensio/distribution-bundle           v5.0.4  Base bundle for Symfony Distributions
sensio/framework-extra-bundle        v3.0.13 This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle              v3.0.5  This bundle generates code for you
sensiolabs/security-checker          v3.0.2  A security checker for your composer.lock
swiftmailer/swiftmailer              v5.4.1  Swiftmailer, free feature-rich PHP mailer
symfony/monolog-bundle               v2.8.2  Symfony MonologBundle
symfony/phpunit-bridge               v2.8.2  Symfony PHPUnit Bridge
symfony/polyfill-intl-icu            v1.1.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring            v1.1.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54               v1.1.0  Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55               v1.1.0  Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/polyfill-php56               v1.1.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70               v1.1.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util                v1.1.0  Symfony utilities for portability of PHP codes
symfony/security-acl                 v2.8.0  Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle           v2.3.11 Symfony SwiftmailerBundle
symfony/symfony                      v2.8.2  The Symfony PHP framework
twig/twig                            v1.24.0 Twig, the flexible, fast, and secure template language for PHP

编辑

按照建议,在解决了一些依赖问题之后,我将 Doctrine 升级到了 2.5。

现在我只有 2 条通知,关于安全方面的内容,我目前正在处理这些内容,基于已弃用的教程。评论故障线路使通知消失。万岁!

【问题讨论】:

  • 可能需要更新到 Doctrine 2.5。我要做的是为我使用的任何版本创建一个新的 Symfony 应用程序,检查供应商版本并相应地更新 composer.json。
  • 我试过了,现在我只有 2 个弃用通知。 2 次刷新后,我猜是因为安全和会话有问题(28 弃用警告)。我将使用新信息进行编辑。
  • 其实就是进步。 2.8 是向 3.0 的过渡。确保您的所有捆绑包都符合 2.8 的预期,然后卷起袖子开始阅读通知。或者回到2.7。 FOSUserBundle 将成为您的大问题。以及所有表单内容。
  • 目前,除了我写的一些不推荐使用的东西外,没有任何通知,我很容易修复。你的教义升级成功了,谢谢@Cerad

标签: symfony doctrine yaml


【解决方案1】:

按照Cerad 的建议,我通过编辑composer.json 并运行composer update 升级到了Doctrine 2.5。

这产生了新的通知,但与我以不推荐使用的方式编写的安全内容相关,很容易修复。

对于遇到相同问题的任何人,请注意您的 composer.json,Doctrine 2.5 需要 php 5.4,而我的某些 config.platform.php 设置为 5.3.9,这阻止了更新。如果您想升级,也请编辑此内容。

【讨论】:

    【解决方案2】:

    将文件名传递给 Yaml::parse() 的功能已被删除。 之前:Yaml::parse($fileName); 之后:Yaml::parse(file_get_contents($fileName));

    来源: https://github.com/symfony/symfony/blob/master/UPGRADE-3.0.md#yaml

    可能您没有使用明确的 Yaml::parse。在您想升级到 3.0 之前,这不是问题。如果你愿意,除了依赖项(可能是学说桥)涵盖的变化之外,你可以。如果不是,你应该坚持使用 Symfony 的 2.7 LTS 版本。

    我刚刚检查了 2.8 也是 LTS。我不确定有什么区别。

    【讨论】:

    • 问题是他不在任何地方使用Yaml::parse。默认情况下,供应商会抛出该错误。
    • 当我意识到自己的错误时,我编辑了答案。我没有仔细阅读。
    • 我不能放弃 3 周的开发并降级到 2.7。另外,2.8 是 LTS,为什么要降级?。
    • 我在 Symfony 网站上进一步检查后编辑了我的答案。如果我在哪里,我会升级到 3.0。实际上我正计划尽快升级我的 2.7 应用程序。
    • 我不确定我能做到,不过我会提交这个想法。我通过将 Doctrine 升级到 2.5 解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2017-08-23
    • 2021-12-05
    • 2019-06-27
    • 2012-03-07
    • 2022-09-25
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    相关资源
    最近更新 更多