title: Accessing the AppKernel environment variable in symfony 2
body: <p>I'm Using symfony 2 and we have 2 configurations, dev and prod. I need to know if I can find out which one im using inside an Entity or Model.</p>
  
  <p>I'm looking for something similar to this code found in AppKernel.php:</p>
  
  <pre><code>$this-&gt;getEnvironment()
  </code></pre>
  
  <p>If I could load the Kernel to call this that would be great but I can't find a way to do this. After looking into this it appears that symfony events may return the Kernel but I don't know how or where to capture these events so that I can call getKernel() on them. <a href="http://symfony.com/doc/current/book/internals.html" rel="noreferrer">http://symfony.com/doc/current/book/internals.html</a></p>
  
  <p>For example, they list this example:</p>
  
  <p>use Symfony\Component\HttpKernel\Event\FilterControllerEvent;</p>
  
  <pre><code>public function onKernelController(FilterControllerEvent $event)
  {
      $controller = $event-&gt;getController();
      // ...
  
      // the controller can be changed to any PHP callable
      $event-&gt;setController($controller);
  }
  </code></pre>
  
  <p>Its unclear to me where to put this block of code. It seems to me that it should go in the Kernel, and if I had the Kernel I wouldn't be having this problem.</p>
  
  <p>My question is, is there an easy way for me to determine if I'm in 'dev' or 'prod' as set in the Kernel, from a Service or Model.
  Thanks</p>