Posted By

nickpro on 07/15/13


Tagged


Versions (?)

ControllerPluginTrait


 / Published in: PHP
 

quick access to frequently used instances

  1. <?php
  2. namespace Gateway\AppBundle\Common;
  3.  
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5.  
  6. trait ControllerPluginTrait
  7. {
  8. public function __construct()
  9. {
  10. if (!$this instanceof Controller) {
  11. throw new Exception(sprintf('Expected instance of Controller, instance of %s given', get_class($this)));
  12. }
  13. }
  14.  
  15. public function getMongo()
  16. {
  17. return $this->get('doctrine_mongodb')->getManager();
  18. }
  19.  
  20. public function getUserRepository()
  21. {
  22. return $this->getMongo()->getRepository('Gateway\UserBundle\Document\User');
  23. }
  24.  
  25. public function getWorkspaceRepository()
  26. {
  27. return $this->getMongo()->getRepository('Gateway\UserBundle\Document\Workspace');
  28. }
  29.  
  30. public function getApplicationManager()
  31. {
  32. return $this->get('gateway.appmanager');
  33. }
  34. }

Report this snippet  

You need to login to post a comment.