2016-07-05 30 views
0

我一直在使用Silex(最初爲1.3)的SimpleUser(https://github.com/jasongrimes/silex-simpleuser)插件。我正在將我的應用程序升級到Silex 2.0。 SimpleUser中的UserProviderInterface實現了ServiceProviderInterface和ControllerProviderInterface。前者現在在Pimple中被定義爲不在Silex中,因爲它在1.3中,並且其註冊方法的參數是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作爲參數實現註冊方法,其中$ app是Silex \ Application實例。 PHPStorm不再反對UserServiceProvider中的註冊方法。如果有人遇到此問題,我會繼續發佈此信息。

+2

好問題,好研究,好答案!用一個具體的例子來更新你的問題可能是一個想法,並提供一個合適的「答案」。 –

回答

0

進一步調試後會有一點點進一步的信息。 SimpleUser UserServiceProvider是用Silex \ ServiceProviderInterface和Silex \ ControllerProviderInterface爲Silex 1.3實現的,其中ServiceProviderInterface提供了註冊和啓動方法。

在Silex 2.0中,ServiceProviderInterface僅提供一種註冊方法,現在位於Pimple命名空間中。 BootableProviderInterface可以提供引導方法和ControlleProviderInterface connect方法,並位於Silex \ API命名空間中。

SimpleUserProvider必須實現所有三個才能在Silex2.0中工作。 register()方法現在需要Pimple \ Container作爲其參數而不是Silex \ Application,而boot()和connect()方法仍然具有Silex \ Application作爲第一個參數。

如 類UserServiceProvider實現 ServiceProviderInterface, BootableProviderInterface, ControllerProviderInterface { 公共功能寄存器(集裝箱$ APP){ ... } 公共功能啓動(應用程序$){ ... } public function connect(Application $ app){ .... } ... }

相關問題