【问题标题】:CakePHP 4.x Authentication 2.x - Fatal Error When InitiatingCakePHP 4.x Authentication 2.x - 启动时的致命错误
【发布时间】:2019-10-31 07:44:10
【问题描述】:

我刚刚重新安装了 CakePHP 4.x(确切地说是4.x-dev)并安装了身份验证插件(2.x-dev)。我在这里遵循快速入门指南:https://github.com/cakephp/authentication/blob/2.x-get/docs/Quick-start-and-introduction.md

我添加了必要的使用声明implements AuthenticationServiceProviderInterface,并添加了getAuthenticationService(ServerRequestInterface $request) 函数和必要的中间件添加,但我收到了一个致命错误:

致命错误:声明 App\Application::getAuthenticationService(Psr\Http\Message\ServerRequestInterface $request) 必须兼容 Authentication\AuthenticationServiceProviderInterface::getAuthenticationService(Psr\Http\Message\ServerRequestInterface $request): Authentication\AuthenticationServiceInterface in /src/Application.php 在第 40 行。

第 40 行是:

class Application extends BaseApplication implements AuthenticationServiceProviderInterface

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    您缺少 Application::getAuthenticationService() 方法的返回类型提示。

    应该和这个https://github.com/cakephp/authentication/blob/master/src/AuthenticationServiceProviderInterface.php#L32类似

    【讨论】:

    • 我确实在这些文档中添加了返回类型提示,并且只有在我添加时才起作用:use Authentication\AuthenticationServiceInterface; 我现在看到它是 2.x 文档的一部分。但是,如果我有 getAuthenticationService(ServerRequestInterface $request, ResponseInterface $response): AuthenticationServiceInterface 和 WORKS 如果只是 getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface(删除 $response 变量),它会再次引发错误 - 所以我不确定分支中是否还需要更改更多内容。
    • 链接不存在了。你能更新一下吗?
    猜你喜欢
    • 1970-01-01
    • 2012-09-16
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 2021-12-31
    • 1970-01-01
    相关资源
    最近更新 更多