title: Observer Pattern in PHP - Correct Practice for Different Events
body: <p>I would like to know if my implementation of the Observer pattern for different events, such as '<code>userLoggedOut</code>', '<code>userRegistered</code>', '<code>userLoggedIn</code>' are correct, below is my simplified code:</p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>$login = new \Observer\Observable\Login;
  $userData = $login-&gt;getData();
  
  $login-&gt;attach( new \Observer\Observer\Email );
  
  $login-&gt;notify( 'userLoggedIn' );
  $login-&gt;notify( 'userLoggedOut', $userData );
  $login-&gt;notify( 'userRegistered' );
  </code></pre>
  
  <p><strong>Login.php</strong></p>
  
  <pre><code>namespace Observer\Observable;
  use Observer\Interfaces;
  
  class Login implements Interfaces\Observable {
  
      private $observers = array();
  
      function attach( Interfaces\Observer $object ) {
  
          $this-&gt;observers[] = $object;
  
      }
  
      function getObservers() {
  
          return $this-&gt;observers;
  
      }
  
      function notify( $action, $data = null ) {
  
          foreach( $this-&gt;observers as $observer ) :
  
              if( method_exists( $observer, $action ) ) $observer-&gt;$action( $data );
  
          endforeach;
  
      }
  
  }
  </code></pre>
  
  <p><strong>Email.php</strong></p>
  
  <pre><code>namespace Observer\Observer;
  use Observer\Interfaces;
  
  class Email implements Interfaces\Observer {
  
      function userLoggedIn( $data = null ) {
  
          echo "email user logged in";
  
      }
  
      function userLoggedOut( $data = null ) {
  
          echo "email user logged out";
  
      }
  
      function userRegistered( $data = null ) {
  
          echo "email user registered";
  
      }
  
  }
  </code></pre>
  
  <p>My question is are there better ways of implementing the Observer pattern when dealing with multiple actions.</p>