title: Constants in Doctrine 2 entities
body: <p>Suppose i'm having the following Doctrine 2 entity:</p>
  
  <pre class="lang-php prettyprint-override"><code>/**
   * @ORM\Entity
   * @ORM\Table(name="users")
   */
  class User {
  
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue
       *
       * @var int
       */
      protected $id;
  
      /**
       * @ORM\Column(length=100)
       *
       * @var string
       */
      protected $name;
  
      /**
       * @ORM\Column(type="integer")
       *
       * @var int
       */
      protected $status;
  }
  </code></pre>
  
  <p>The User can have several statuses, for example:  Pending, Active, Suspended. These statuses are needed throughout the code (services, repositories, etc.) and also in the UI layer (a User edit form would display them in a dropdown). </p>
  
  <p>In order to avoid defining them in multiple places, what i've done so far was to use a class to hold them all (all the application's constants), and it looks somewhat like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>class App_Constants extends Zrzr_Constants
  {
  
      protected static $_constants = array( 
          'users' =&gt; array( 
              'status' =&gt; array( 
                  0 =&gt; 'Pending', 
                  1 =&gt; 'Active',
                  2 =&gt; 'Suspended' ) ) );
  
  }
  </code></pre>
  
  <p>The base class (Zrzr_Constants) would offer some methods to retrieve them, and it looks like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>class Zrzr_Constants
  {
      protected static $_constants = array();
  
      public static function getConstantValues( $key, $subkey )
      {
          // ...
      }
  
      public static function getConstantByName( $name )
      {
          // ...
      }
  }
  </code></pre>
  
  <p>Common usage would be:</p>
  
  <pre class="lang-php prettyprint-override"><code>// example of retrieval by constant name ... it would return an integer
  $pendingStatus = App_Constants::getConstantByName( 'USERS.STATUS.PENDING' );
  
  // example of retrieval for UI display purposes ... would return an array
  $statuses = App_Constants::getConstantValues('users', 'status');
  </code></pre>
  
  <p>Of course this means that there are some limitations in that the constant labels cannot contain dots, but i can live with it.</p>
  
  <p>Using Doctrine 2 and going the DDD way however, tells me that the 'status' field should be in fact a 'value object' (but Doctrine 2 does not support value objects yet), or at least that i should have the constants defined within the entity (using const). </p>
  
  <p>My question is how would i do this so that i avoid constant redefinition for the UI layer? I need to have access to the constant by name (in the code) and to have all the possible values for such a field in the case of a UI dropdown (for example).</p>