【发布时间】:2016-11-06 22:13:08
【问题描述】:
我一直在为 Silex(最初为 1.3)使用 SimpleUser (https://github.com/jasongrimes/silex-simpleuser) 插件。我正在将我的应用程序升级到 Silex 2.0。 SimpleUser 中的 UserProviderInterface 实现了 ServiceProviderInterface 和 ControllerProviderInterface。前者现在在 Pimple 中定义,而不是像在 1.3 中那样在 Silex 中定义,并且它的 register 方法的参数是 Pimple 容器而不是 Silex 应用程序(它扩展了 Pimple 容器类)。 PHPStorm 将此标记为 PHP 致命错误(声明必须与 ServiceProviderInterface-->register(pimple: \Pimple\Container) 兼容)。我不确定 PHPStorm 中的检查是否过于严格,或者这是一个严重的问题。
其他帖子表明您不能简单地覆盖接口定义 (Can you override interface methods with different, but "compatible", signatures?)(也可以是 http://php.net/manual/en/language.oop5.interfaces.php)。
我刚刚解决了我的问题。 Silex 2.0 Provider 说明表明您可以使用 Container $app 作为参数实现 register 方法,其中 $app 是一个 Silex\Application 实例。 PHPStorm 不再反对 UserServiceProvider 中的 register 方法。我将继续发布此内容,以防其他人遇到此问题。
【问题讨论】:
-
好问题,好研究,好答案!用一个具体的例子来更新你的问题,并提供一个适当的“答案”可能是一个想法。
标签: php service interface silex provider