Exemple #1
0
 /**
  * Inject a helper instance with the registered translator
  *
  * @param ContainerInterface|Helper\HelperInterface $first helper instance
  *     under zend-servicemanager v2, ContainerInterface under v3.
  * @param ContainerInterface|Helper\HelperInterface $second
  *     ContainerInterface under zend-servicemanager v3, helper instance
  *     under v2. Ignored regardless.
  */
 public function injectTranslator($first, $second)
 {
     if ($first instanceof ContainerInterface) {
         // v3 usage
         $container = $first;
         $helper = $second;
     } else {
         // v2 usage; grab the parent container
         $container = $second->getServiceLocator();
         $helper = $first;
     }
     if (!$helper instanceof TranslatorAwareInterface) {
         return;
     }
     if (!$container) {
         // Under zend-navigation v2.5, the navigation PluginManager is
         // always lazy-loaded, which means it never has a parent
         // container.
         return;
     }
     if ($container->has('MvcTranslator')) {
         $helper->setTranslator($container->get('MvcTranslator'));
         return;
     }
     if ($container->has('Zend\\I18n\\Translator\\TranslatorInterface')) {
         $helper->setTranslator($container->get('Zend\\I18n\\Translator\\TranslatorInterface'));
         return;
     }
     if ($container->has('Translator')) {
         $helper->setTranslator($container->get('Translator'));
         return;
     }
 }
 /**
  * Inject a helper instance with the registered event manager
  *
  * @param ContainerInterface|Helper\HelperInterface $first helper instance
  *     under zend-servicemanager v2, ContainerInterface under v3.
  * @param ContainerInterface|Helper\HelperInterface $second
  *     ContainerInterface under zend-servicemanager v3, helper instance
  *     under v2. Ignored regardless.
  */
 public function injectEventManager($first, $second)
 {
     if ($first instanceof ContainerInterface) {
         // v3 usage
         $container = $first;
         $helper = $second;
     } else {
         // v2 usage; grab the parent container
         $container = $second->getServiceLocator();
         $helper = $first;
     }
     if (!$container) {
         // Under zend-navigation v2.5, the navigation PluginManager is
         // always lazy-loaded, which means it never has a parent
         // container.
         return;
     }
     if (!$helper instanceof EventManagerAwareInterface) {
         return;
     }
     if (!$container->has('EventManager')) {
         // If the container doesn't have an EM service, do nothing.
         return;
     }
     $events = $helper->getEventManager();
     if (!$events || !$events->getSharedManager() instanceof SharedEventManagerInterface) {
         $helper->setEventManager($container->get('EventManager'));
     }
 }