【问题标题】:Symfony 2.8: ResourceInterface::isFresh() is deprecated since 2.8Symfony 2.8:ResourceInterface::isFresh() 自 2.8 起已弃用
【发布时间】:2016-03-12 08:31:22
【问题描述】:

升级到 Symfony 到 2.8 后,发现很多 deprecation 警告:

“Symfony\Bundle\AsseticBundle\Config\AsseticResource”类是 通过 ResourceInterface::isFresh() 执行资源检查, 自 2.8 起已弃用,将在 3.0 中删除(54 次)

堆栈(来自 Symfony 分析器)

BCResourceInterfaceChecker::isFresh() (called from bootstrap.php.cache at line 3061)
ResourceCheckerConfigCache::isFresh() (called from ResourceCheckerConfigCacheFactory.php at line 45)
ResourceCheckerConfigCacheFactory::cache() (called from classes.php at line 1328)
Router::getMatcher() (called from classes.php at line 1288)
Router::match() (called from classes.php at line 7170)
Router::match() (called from classes.php at line 2086)
RouterListener::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 bootstrap.php.cache at line 3178)
HttpKernel::handleRaw() (called from bootstrap.php.cache at line 3151)
HttpKernel::handle() (called from bootstrap.php.cache at line 3302)
ContainerAwareHttpKernel::handle() (called from bootstrap.php.cache at line 2498)
Kernel::handle() (called from app_dev.php at line 29)

我用过的升级:

composer.phar update symfony/symfony --with-dependencies

这是我的 composer.json

{
    "name": "framework/symfony",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "": "src/"
        }
    },
    "require": {
        "php": ">=5.3.9",
        "symfony/symfony": "2.8.*",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0"
    },
    "require-dev": {
        "sensio/generator-bundle": "~2.3"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }
    }
}

如何解决这个弃用警告?

【问题讨论】:

标签: php symfony symfony-2.8


【解决方案1】:

您是否尝试过将资产包版本更新到最新版本?

"symfony/assetic-bundle": "~2.7", 

【讨论】:

【解决方案2】:

一些谷歌搜索发现:https://knpuniversity.com/screencast/symfony3-upgrade/fix-deprecations-in-bundles

他们链接到 Assetic GitHub 页面,该页面声称 2.7.1 已为 Symfony 3 做好准备。但显然不是。就这么容易。 Assetic 只是没有为 symfony 3 做好准备,所以它在 2.8 中产生了很多弃用通知。 merge request to fix this 尚未合并。

【讨论】:

    【解决方案3】:

    dev-master 分支已经与 Symfony 3 兼容了几个星期了。更新使用没有错。

    composer.json

    ....
    "symfony/assetic-bundle": "dev-master",
    ....
    

    composer 更新 symfony/assetic-bundle

    所有错误都会消失。

    【讨论】:

    • 如果今天 2.7.1 是最新版本,而 2.7.1 有问题,您会选择哪个版本?看起来我错过了什么。
    • 您将选择正在积极开发的版本(因此标记为 dev-master),该版本始终添加新功能(并删除折旧代码)但尚未尚未经过彻底测试与第 3 方扩展的兼容性。通常,dev-master 非常稳定,但由于人们没有时间始终对其进行测试,因此需要很长时间才能进入稳定状态,但它现在可以解决您的问题。
    • Tnx @Don,我一直(错误地)认为 dev-master 会将我指向最新的稳定版本(如本例中的 2.7.1)
    • @userfuser 随时 :) 这是一个常见的误解。
    猜你喜欢
    • 2016-06-24
    • 2017-05-19
    • 2016-08-04
    • 1970-01-01
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多