根据官方文档来进行依赖注入,会出现Method ReflectionParameter::getClass() is deprecated的问题,该问题的产生是因为php8不支持getClass()写法,得用getType()的写法
modify.php文件composer.json文件,新增post-install-cmd、post-update-cmd项
"scripts": {
"post-install-cmd": [
"php modify.php"
],
"post-update-cmd": [
"php modify.php"
]
}modify.php文件
<?php
$AnnotationBasedAutowiring_file = 'vendor/php-di/php-di/src/Definition/Source/AnnotationBasedAutowiring.php';
if (file_exists($AnnotationBasedAutowiring_file)) {
// 读取文件内容
$content = file_get_contents($AnnotationBasedAutowiring_file);
// 检查文件是否成功读取
if ($content !== false) {
// 进行字符串替换
$updatedContent = str_replace('$parameter->getClass()', '$parameter->getType()', $content);
// 将替换后的内容写回文件
file_put_contents($AnnotationBasedAutowiring_file, $updatedContent);
}
}
这样的话,后续composer安装或者更新的同时去执行该文件
大佬厉害,修改,再composer 更新一下,就OK了
为啥不直接提pr?或者自建仓库用自己的仓库,等官方修改了就用官方的。