Skip to content

Instantly share code, notes, and snippets.

@konradpodgorski
Created June 13, 2013 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konradpodgorski/5777189 to your computer and use it in GitHub Desktop.
Save konradpodgorski/5777189 to your computer and use it in GitHub Desktop.
Reusable AbstractController with shortcuts for frequently used methods
<?php
namespace KP\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* Class AbstractController
*
* @package KP\MainBundle\Controller
*/
abstract class AbstractController extends Controller
{
/**
* @return \Symfony\Component\Security\Core\SecurityContext
*/
public function getSecurityContext()
{
return $this->container->get('security.context');
}
/**
* @param string $permission
* @param null $domainObject
*
* @return bool
*/
public function isGranted($permission, $domainObject = null)
{
return $this->getSecurityContext()->isGranted($permission, $domainObject);
}
/**
* @param string|null $name
*
* @return \Doctrine\ORM\EntityManager
*/
public function getManager($name = null)
{
return $this->getDoctrine()->getManager($name);
}
/**
* @return \FOS\UserBundle\Model\UserManager
*/
public function getUserManager()
{
return $this->container->get('fos_user.user_manager');
}
/**
* Add new flash message to the FlashBag
*
* @param string $type
* @param string $message
*/
public function addFlash($type, $message)
{
$this->container->get('session')->getFlashBag()->add($type, $message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment