duanju8308 2014-05-26 13:43
浏览 32
已采纳

Zend Framework 2 - 在HydratorPluginManager中设置serviceLocator不起作用

I am using a HydratorPluginManager (Zend\Stdlib\Hydrator\HydratorPluginManager) to manage my hydrators in one single spot and to let the manager take care of validation of my hydrators (meaning checking if my hydrators properly implement the HydratorInterface).

I have some hydrators that I created using factories like this:

'service_manager' => array(
    'factories' => array(
        'My\Hydrators\SomeHydrator' => 'My\Hydrators\SomeHydratorFactory'
    )
)

After registering the factories in my config file these hydrators are without any problem available in my ServiceManager using $serviceManager->get($name). Now I would like to connect my ServiceManager to my HydratorManager so that if I ask for a certain hydrator using:

$hydratorPluginManager->get($name)

where $name is the alias used for registering. So in this example it would be:

$hydratorPluginManager->get('My\Hydrators\SomeHydrator');

My idea was that if I connect my ServiceManager like this:

$hydratorPluginManager->setServiceLocator($serviceManager)

It should work. But it doesn't and I am very confused why this is not working...

Am I missing something here?

  • 写回答

1条回答 默认 最新

  • dousou3027 2014-05-27 08:55
    关注

    You could just put the hydrators in the plugin manager directly. The hydrator plugin manager is configured in the same way it is for the service manager (invokables, factories, etc), only the config key is different, hydrators instead of service_manager

    You just need to move your factories from service_manager to hydrators ...

    'hydrators' => array(
        'factories' => array(
            'My\Hydrators\SomeHydrator' => 'My\Hydrators\SomeHydratorFactory'
        )
    ),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA