问题描述
从CakePHP Framework中删除一个插件以及与之相关的所有代码行后,我的vendor->composer
文件夹中autoload_static.php
的getInitializer
函数出现错误:
After deleting a plugin from my CakePHP Framework and all the lines of code associated with it I get an error in the getInitializer
function of the autoload_static.php
in my vendor->composer
folder:
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$prefixesPsr0;
$loader->classMap = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$classMap;
}, null, ClassLoader::class);
}
所有前缀和classMap
带下划线,并且错误消息显示:
All the prefixes and the classMap
are underlined and the error message says:
我对PHP还是很陌生,所以我的问题是如何处理此错误?我想只删除这4行代码是不安全的.
I'm fairly new to PHP, so my question would be how to handle this error? I suppose it's not safe to just delete this 4 lines of code.
我已经尝试更新作曲家并使PhpStorm中的缓存/重新启动无效.
I already tried to update composer and invalidate caches/restart in PhpStorm.
编辑1
我当然不应该从作曲家文件中手动删除与旧插件相关的代码行.
I surely shouldn't have deleted the lines of code related to the old plugin manually out of the composer files.
作曲家诊断:正在检查composer.json:失败require.cakephp/plugin-installer:应避免未绑定版本限制(*)检查平台设置:失败PHP使用的OpenSSL库(0.9.8y)不支持TLSv1.2或TLSv1.1.如果可能,您应该将OpenSSL升级到1.0.1或更高版本.检查git设置:确定正在检查与packagist的http连接:警告:通过不安全的协议http访问packagist.org.
composer diagnose:Checking composer.json: FAILrequire.cakephp/plugin-installer : unbound version constraints (*) should be avoidedChecking platform settings: FAILThe OpenSSL library (0.9.8y) used by PHP does not support TLSv1.2 or TLSv1.1.If possible you should upgrade OpenSSL to version 1.0.1 or above.Checking git settings: OKChecking http connectivity to packagist: Warning: Accessing packagist.org over http which is an insecure protocol.
由于该项目不太旧,可能是将其完全删除并从头开始重新启动的最简单方法,还是有一个简单的解决方案?
As the project isn't too old, it might be the easiest way just to delete it completely and restart from scratch or is there an easy solution to that?
推荐答案
从技术上讲,这些行被错误地突出显示为错误,甚至在您修改代码之前,它们仍被突出显示为错误.
The lines are technically incorrectly highlighted as errors, and they were highlighted as errors even before you've modified the code.
代码会将特定的对象和范围绑定到闭包,在这种情况下,它将把$loader
对象(ClassLoader
的实例)绑定到ClassLoader::class
范围.这将导致闭包以使私有方法可见的方式绑定到$loader
对象,因此在运行时不会出错.
The code will bind a specific object and scope to a closure, in this case it will bind the $loader
object (an instance of ClassLoader
) with the ClassLoader::class
scope. This will cause the closure to be bound to the $loader
object in a way that makes private methods visible to it, and hence things won't error out at runtime.
所以问题就在于PhpStorm解析器还不够聪明(至今)无法识别这一点.
So the problem is just that the PhpStorm parser isn't smart enough (yet) to recognize this.
另请参见 http://www.php.net/manual/zh-CN/closure.bind.php
See also http://www.php.net/manual/en/closure.bind.php
就您的其他作曲家问题而言,应该始终可以安全删除供应商文件,即vendor
文件夹通常应仅包含通过作曲家安装的代码,这意味着万一您将事情搞砸了,则应该能够简单地删除vendor
文件夹,如有必要,修复您的composer.json
文件(并删除composer.lock
文件),然后再次运行composer update
或composer install
命令.
As far as your other composer problems are concerned, vendor files should always be safe to delete, ie the vendor
folder should normally only contain code installed through composer, which means that in case you screw things up big, you should be able to simply delete the vendor
folder, fix up your composer.json
file (and delete the composer.lock
file) if necessary, and then just run the composer update
or composer install
command again.
这篇关于“成员具有私人访问错误";使用PhpStorm在CakePHP中删除插件后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!