title: How to trigger an event attached to the Shared Event Manager in ZF2?
body: <p>An event attached to a (local) event manager</p>
  
  <pre><code>public class myClass implements EventManagerAwareInterface {
      ...
      public function __construct(...) {
          ...
          $this-&gt;getEventManager()-&gt;attach('doEvent', function ($e) {
              $event = $e-&gt;getName();
              $params = $e-&gt;getParams();
              printf(
                  'Handled event "%s", with parameters %s',
                  $event,
                  json_encode($params)
              );
          });
      }
      ...
      public function getEventManager() {
          if (!$this-&gt;eventManager) {
              $this-&gt;setEventManager(new EventManager());
          }
          return $this-&gt;eventManager;
      }
      public function setEventManager(EventManagerInterface $eventManager) {
          $eventManager-&gt;setIdentifiers(array(
              __CLASS__,
              get_class($this),
              'exampleIdentifier',
          ));
          $this-&gt;eventManager = $eventManager;
          return $this;
      }
  }
  </code></pre>
  
  <p>can be triggered locally as follows:</p>
  
  <pre><code>public class myClass {
      ...
      public function doWhatEver(...) {
          $this-&gt;getEventManager()-&gt;trigger('doEvent', null, ['foo' =&gt; 'bar', 'baz' =&gt; 'bat']);
      }
      ...
  }
  </code></pre>
  
  <p>If I understand the Shared Event Manager correctly, it's a central register of events and listeners, bundled to <code>identifiers</code>. It is known by every (local) event manager. (Btw.: How does this ZF2 magic work?) Every event manager has access 1. to the listeners registered in it and 2. to the shared event manager's "pool". Attaching an event to this pool is similar to the common event attaching to an event manager, but requires an additional parameter -- <code>identifier</code> (the key of the "listeners bundle" in the shared "pool"):</p>
  
  <pre><code>this-&gt;getEventManager()-&gt;getSharedManager()-&gt;attach('exampleIdentifier', 'doEvent', function ($e) {
      ...
  });
  </code></pre>
  
  <p>The triggering from the same class is exactly identical:</p>
  
  <pre><code>$this-&gt;getEventManager()-&gt;trigger('doEvent', null, ['foo' =&gt; 'bar', 'baz' =&gt; 'bat']);
  </code></pre>
  
  <p>Now I want to move the trigger-call to another class. But I don't understand, how to pass the correct <code>identifier</code>. <strong>How to trigger an event attached to the Shared Event Manager from a class, that has a <code>ServiceManager</code> with a different <code>identifier</code> / <code>identifier</code>s set?</strong></p>