title: Doctrine2 - Trigger event on property change (PropertyChangeListener)
body: <p><em>I am not writing "what did I try" or "what is not working" since I can think of many ways to implement something like this. But I cannot believe that no one did something similar before and that is why I would like to ask the question to see what kind of Doctrine2 best practices show up.</em></p>
  
  <hr>
  
  <p>What I want is to trigger an event on a property change. So let's say I have an entity with an <code>$active</code> property and I want a <code>EntityBecameActive</code> event to fire for each entity when the property changes from <code>false</code> to <code>true</code>.</p>
  
  <p>Other libraries often have a <code>PropertyChanged</code> event but there is no such thing available in Doctrine2.</p>
  
  <p>So I have some entity like this:</p>
  
  <pre><code>&lt;?php
  
  namespace Application\Entity;
  
  class Entity
  {
      /**
       * @var int
       * @ORM\Id
       * @ORM\Column(type="integer");
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @var boolean
       * @ORM\Column(type="boolean", nullable=false)
       */
      protected $active = false;
  
      /**
       * Get active.
       *
       * @return string
       */
      public function getActive()
      {
          return $this-&gt;active;
      }
  
      /**
       * Is active.
       *
       * @return string
       */
      public function isActive()
      {
          return $this-&gt;active;
      }
  
      /**
       * Set active.
       *
       * @param bool $active
       * @return self
       */
      public function setActive($active)
      {
          $this-&gt;active = $active;
          return $this;
      }
  }
  </code></pre>