Created
March 21, 2016 11:14
-
-
Save jenkoian/948437a9a5fa56824627 to your computer and use it in GitHub Desktop.
PermissionFacade
This file contains 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 | |
//... | |
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