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条)

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了