What is the sense of naming invokables like classes?

前端 未结 3 1812
眼角桃花
眼角桃花 2021-02-04 21:44

I\'m going trough ZfcUser to learn more about modules in Zend Framework 2. In the Module.php you can see

\'invokables\' => array(
  \'ZfcUser\\Authentication\         


        
3条回答
  •  再見小時候
    2021-02-04 21:53

    There is no convention but I do think you should consider how the invokables will be used.

    For example the first three rely on an interface called ServiceManagerAwareInterface therefore these instances need to come out of the ServiceLocator to function as intended. Given that they are fully qualified class names, I would assume that the ZfcUser developers do not envisage people overriding these.

    And the latter two are aliased, so if a developer wanted to override these invokables it would be a straightforward task. An example of this is the developer chooses to extend ZfcUser\Service\User to add/modify functionality, then creates line in his module's invokables:

    'invokables' => array(
      'zfcuser_user_service' => 'MyModule\Service\ZfcUser',
    ),
    

    Then any code using zfcuser_user_service would receive an instance of MyModule\Service\ZfcUser rather than ZfcUser\Service\User.

提交回复
热议问题