duanli5662 2018-04-12 14:44
浏览 38
已采纳

使用EasyExtends时,方法签名显然不匹配

I am working on a pre-existing project that uses EasyExtends to extend Sonata's page bundle. The project is based on Symfony 3.3.

There already exists in this project a class in namespace Application\Sonata\PageBundle\Admin called PageAdmin extending BasePageAdmin. It contains definitions two functions -- getPageTypes and configureFormFields.

When I try to clone the function configureTabMenu from the vendor copy of this class -- where it works just fine -- to the Application copy, I get the following complaint from the application:

Warning: Declaration of Application\Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Application\Sonata\PageBundle\Admin\MenuItemInterface $menu, $action, ?Application\Sonata\PageBundle\Admin\AdminInterface $childAdmin = NULL) should be compatible with Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Knp\Menu\ItemInterface $menu, $action, ?Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) in . (which is being imported from "/usr/src/app/app/config/routing.yml"). Make sure there is a loader supporting the "sonata_admin" type.

This is frankly a bit more than I easily understand. Is there a simple way to override the existing configureFormFields() method from my vendor folder?

====

Edit #1: Removing the type hinting (which is ill-advised as a long-term strategy but useful for debugging) subs one warning for another. I then get this warning text:

Warning: Declaration of Application\Sonata\PageBundle\Admin\PageAdmin::configureTabMenu($menu, $action, $childAdmin = NULL) should be compatible with Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Knp\Menu\ItemInterface $menu, $action, ?Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) in . (which is being imported from "/usr/src/app/app/config/routing.yml"). Make sure there is a loader supporting the "sonata_admin" type.

====

Edit #2: Changing the method signature to Knp\Menu\ItemInterface $menu, $action, Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL gives me this instead:

Warning: Declaration of Application\Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Application\Sonata\PageBundle\Admin\Knp\Menu\ItemInterface $menu, $action, ?Application\Sonata\PageBundle\Admin\Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) should be compatible with Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Knp\Menu\ItemInterface $menu, $action, ?Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) in . (which is being imported from "/usr/src/app/app/config/routing.yml"). Make sure there is a loader supporting the "sonata_admin" type.

  • 写回答

2条回答 默认 最新

  • dongshuohuan5291 2018-04-13 09:35
    关注

    It turned out that I was missing two use statements. I copied these from the class I was cloning from:

    use Sonata\AdminBundle\Admin\AdminInterface;
    use Knp\Menu\ItemInterface as MenuItemInterface;
    

    ... and everything worked.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?