Return to Snippet

Revision: 64213
at July 15, 2013 23:14 by nickpro


Initial Code
<?php
namespace Gateway\AppBundle\Common;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

trait ControllerPluginTrait
{
    public function __construct()
    {
        if (!$this instanceof Controller) {
            throw new Exception(sprintf('Expected instance of Controller, instance of %s given', get_class($this)));
        }
    }
    
    public function getMongo()
    {
        return $this->get('doctrine_mongodb')->getManager();
    }
    
    public function getUserRepository()
    {
        return $this->getMongo()->getRepository('Gateway\UserBundle\Document\User');
    }
    
    public function getWorkspaceRepository()
    {
        return $this->getMongo()->getRepository('Gateway\UserBundle\Document\Workspace');
    }
    
    public function getApplicationManager()
    {
        return $this->get('gateway.appmanager');
    }
}

Initial URL

                                

Initial Description
quick access to frequently used instances

Initial Title
ControllerPluginTrait

Initial Tags

                                

Initial Language
PHP