Created
June 13, 2013 20:47
-
-
Save konradpodgorski/5777189 to your computer and use it in GitHub Desktop.
Reusable AbstractController with shortcuts for frequently used methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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