最近我在Symfony2中从 symfony.com 上可用的BETA版本开始了一个项目
过了一会儿,我需要升级到主分支,所以我从github检索了最新的,并在vendor/symfony中切换了它。
但是,我的引导.php.cache和bootstrap_cache.php.cache没有升级,这产生了错误。
我尝试清除symfony缓存,但无济于事。
如何更新这些文件以与我的项目相对应?
在 2.0 版本中,原始文件在这里:
./vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
编辑:在2.3版中,文件在这里
vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
如果运行 composer update
命令,您还将更新项目依赖项,这不是此处所需的行为。如果这样做,则必须测试新更改,以查看它们是否确实以某种方式影响了您的应用程序。
因此,如果您只想重建引导缓存文件,那么我建议您运行 post-update-cmd 命令。
因此,您应该使用:
composer run-script post-update-cmd
在我的情况下执行以下脚本(请参阅 composer.json):
"scripts": {
"post-install-cmd": [
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Mopa\Bundle\BootstrapBundle\Composer\ScriptHandler::postInstallSymlinkTwitterBootstrapSass"
]
}
请注意,您还可以在其中创建一组新的脚本来重建引导程序文件并清除缓存而不安装资产等:
"scripts": {
"reset-bootstrap-cmd": [
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache"
]
}
然后。。。 composer run-script reset-bootstrap-cmd
在最新的 2.1.0-DEV 中,实际脚本在这里:
./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
我正在使用Symfony Standard 2.0.9(没有供应商)。
要更新bootstrap.php.cache
,只需运行
php bin/vendors update
这将更新所有供应商(包括Symfony本身),并始终为您调用该build_bootstrap.php
脚本。
你试过跑步吗:
php bin/build_bootstrap.php
这将重新生成引导程序文件
您可能更喜欢使用composer install
,它将系统"重新安装"到composer.lock
文件中定义的状态,并生成自动加载和引导.php.cache。使用 composer update
会更新所有软件包并更改系统的状态。
我觉得build_bootstrap脚本总是在更改位置:)
因此,如果您正在使用多个Symfony版本并且不知道build_bootstrap在哪里,这将解决问题(仅限Linux/Mac):
$ cd vendor/
$ find . -name build_bootstrap.php
我无法修复引导缓存上的问题,也无法更新它. 我得到了很多这样的
[Symfony\Component\Debug\Exception\ContextErrorException] 警告:在/home/sites/fuji/app/bootstrap.php.cache 第 2870 行中为 foreach() 提供的参数无效
脚本 sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache 处理因异常而终止的更新后 cmd 事件
尽管它们是很好的建议,并且我确实尝试在备份后重建引导缓存文件,并且运行composer update
这些仍然给我带来了同样的问题。
为我提供的解决方案:我用上面有站点文件进入 PC, rm -rf app/cache/* -R
删除了缓存目录中的所有内容,然后我能够同时运行作曲家更新和清除缓存等。没有问题。
搜索"build_bootstrap.php"所在的位置。
对于我在 Symfony3.4 中的情况
php ./vendor/sensio/distribution-bundle/Resources/bin/build_bootstrap.php