Exemplo n.º 1
0
 /**
  * Check if user has permission to access specific route
  *
  * @param User $user
  * @param $route
  * @return bool
  */
 public function checkPermissions(User $user, $route)
 {
     //Check if access exists for current role
     $roleAccesses = $user->getRole()->getAccesses();
     foreach ($roleAccesses as $access) {
         if ($access->getRoute() === $route) {
             return true;
         }
     }
     //Check is access exists for particular user
     $userAccesses = $user->getAccesses();
     foreach ($userAccesses as $access) {
         if ($access->getRoute() === $route) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * PermissionDenied constructor.
  * @param User $user
  * @param int $route
  */
 public function __construct(User $user, $route)
 {
     parent::__construct(sprintf('User "%s" does not have permission for  "%s" route.', $user->getUsername(), $route));
 }