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:


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


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


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

Am I missing something here?

图片转代码服务由CSDN问答提供 功能建议

我正在使用 HydratorPluginManager (Zend \ Stdlib \ Hydrator \ HydratorPluginManager)来管理我的 在一个单一的位置给水槽,并让管理员负责我的水化器的验证(意味着检查我的水化器是否正确实现了 HydratorInterface )。

我有一些 我使用这样的工厂创建的水合器:

 'service_manager'=> 数组(
'我的\ Hydrators \ SomeHydrator'=>'我的\ Hydrators \ SomeHydratorFactory'
 \  n 

在我的配置文件中注册工厂后,使用 $ serviceManager-> get($ name),我的 ServiceManager 中没有任何问题。 现在我想将 ServiceManager 连接到我的 HydratorManager ,这样如果我要求使用某个保湿器:

   $ hydratorPluginManager-> get($ name)

其中 $ name 是用于注册的别名。 所以在这个例子中它将是:

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

我的想法是,如果我像这样连接我的 ServiceManager

  $ hydratorPluginManager-> setServiceLocator($ serviceManager)

它应该有效。 但它没有,我很困惑为什么这不起作用...


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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'
    解决 无用
    打赏 举报

相关推荐 更多相似问题