title: Event-driven architecture and hooks in PHP
body: <p>I am planning on working on a game that has a PHP back-end to communicate with the data repository. I was thinking about it and concluded that the best design paradigm to follow for our game would be event driven. I am looking to have an achievement system (similar to the badges system of this website) and basically I would like to be able to hook these "achievement checks" into a number of different events that occur in the game. ie:</p>
  
  <p>When a user does action X hook Y is fired and all attached functions are called to check against an achievement requirement.</p>
  
  <p>In structuring the architecture like this I will allow for new achievements to be added easily as all I will have to do is add the checking function to the proper hook and everything else will fall into place.</p>
  
  <p>I'm not sure if this is a great explanation of what I intend to do, but in any case I am looking for the following:</p>
  
  <ol>
  <li>Good reference material on how to code an event-driven application</li>
  <li>Code snippet(s) showing how to put a "hook" in a function in PHP</li>
  <li>Code snippet(s) showing how to attach a function to the "hook" mentioned in point 2</li>
  </ol>
  
  <p>I have a few ideas as to how to accomplish 2) and 3) but I was hoping that somebody well-versed in the matter could shed some light on best practices.</p>
  
  <p>Thank you in advance!</p>