Skip to content

Instantly share code, notes, and snippets.

@jenkoian
Created March 21, 2016 11:14
Show Gist options
  • Save jenkoian/948437a9a5fa56824627 to your computer and use it in GitHub Desktop.
Save jenkoian/948437a9a5fa56824627 to your computer and use it in GitHub Desktop.
PermissionFacade
<?php
//...
class PermissionFacade
{
/**
* Global static helper for using isGranted from legacy codebase.
* @param $attributes
* @param null $object
* @return bool|void
*/
public static function isGranted($attributes, $object = null)
{
global $kernel;
if ($kernel === null) {
throw new \RuntimeException(‘Kernel is not available.’);
}
try {
return $kernel->getContainer()->get(‘security.authorization_checker’)->isGranted($attributes, $object);
} catch (AuthenticationCredentialsNotFoundException $e) {
// If here it means we’re trying to check the users credentials but they are not logged in, therefore false
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment