get a role scope by his parameters. The role scope is persisted if it
doesn't exists in database.

@param Scope $scope
@param string $role
@return RoleScope
188439
protected function getPersistentRoleScopeBy($role, Scope $scope = null) 
    {
        $em = $this->getDoctrine()->getManager();
        
        $roleScope = $em->getRepository('ChillMainBundle:RoleScope')
                ->findOneBy(array('role' => $role, 'scope' => $scope));
        
        if ($roleScope === NULL) {
            $roleScope = (new RoleScope())
                    ->setRole($role)
                    ->setScope($scope)
                    ;
            
            $em->persist($roleScope);
        }
        
        return $roleScope;
    }
1052363
public static function getGlobalScope($scope)
    {
        if (! is_string($scope)) {
            $scope = get_class($scope);
        }

        return array_get(static::$globalScopes, static::class.'.'.$scope);
    }
664240
public static function getSetting($scope, $key)
    {
        if (!count(self::$settings)) {
            self::load();
        }

        if (isset(self::$settings[$scope][$key])) {
            return self::$settings[$scope][$key];
        }

        return null;
    }
1025512
public function getRoleChildren($role) {
        $children = array();
        if (Zend_Registry::isRegistered('Zend_Acl')) {
            $acl = Zend_Registry::get('Zend_Acl');
            $roles = $acl->getRoles();

            foreach ($roles as $potentialChild) {
                if ($acl->inheritsRole($potentialChild, $role)) {
                    $children[] = $potentialChild;
                }
            }
        }
        return $children;
    }
833307
public function a($role)
    {
        $roles = func_get_args();

        return $this->clipboard->checkRole($this->authority, $roles, 'or');
    }
820962
public function getRole($current = true)
    {
        if ($current && $this->_hasVar('current_user_role')) {
            return $this->_getRole('current_user_role');
        }
        return $this->_getRole('user_role');
    }
960909
public function withScope($scope)
    {
        if ($scope == Grid\Exporter::SCOPE_ALL) {
            return $this;
        }

        list($scope, $args) = explode(':', $scope);

        if ($scope == Grid\Exporter::SCOPE_CURRENT_PAGE) {
            $this->grid->model()->usePaginate(true);
        }

        if ($scope == Grid\Exporter::SCOPE_SELECTED_ROWS) {
            $selected = explode(',', $args);
            $this->grid->model()->whereIn($this->grid->getKeyName(), $selected);
        }

        return $this;
    }
1217724
public function getGlobalScope($scope)
    {
        return array_first($this->globalScopes, function ($key, $value) use ($scope) {
            return $scope instanceof $value;
        });
    }
900735
public function scoped(Scope $scope)
	{
		if($scope instanceof Dependent)
		{
			$this->scope = NULL;
		}
		else
		{
			$this->scope = get_class($scope);
		}
		
		return $this;
	}
582395
public function getSubRoles(Role $role) {
		
		$parentName = $role->getRoleName();
		$subRoles = [];
		
		if(array_key_exists($role->getRoleName(), $this->mappedRoleNames)) {
			
			foreach($this->mappedRoleNames[$parentName] as $subRoleName) {
				$subRoles[] = new Role($subRoleName);
			}
			
		}
		
		return $subRoles;

	}
1190327
public function hasRole($role)
    {
        return is_null($this->roles) || in_array($role, $this->roles, true);
    }
569749
public function getRolePermissions(Role $role)
    {
        $key = $this->getRoleKey($role);

        // If we've saved the caller permissions we don't need to fetch them again.
        if (array_key_exists($key, $this->rolePermissions)) {
            return $this->rolePermissions[$key];
        }

        $results = $this->getTable()->where('role', $role->getRoleName())->get()->toArray();

        return $this->rolePermissions[$key] = PermissionFactory::createFromData($results);
    }
748480
public static function roleGrant($role) {
		// add roles
		if (!empty($role)) {
			// initialize roles array
			if (!isset($_SESSION['numbers']['user']['roles'])) {
				$_SESSION['numbers']['user']['roles'] = [];
			}
			if (!is_array($role)) $role = [$role];
			$_SESSION['numbers']['user']['roles'] = array_unique(array_merge($_SESSION['numbers']['user']['roles'], $role));
		}
	}
193318
public function scopeRole($query, $role, $column = null)
    {
        if (is_null($role)) {
            return $query;
        }

        return $query->whereHas('roles', function ($query) use ($role, $column) {
            if (is_array($role)) {
                $queryColumn = !is_null($column) ? $column : 'roles.slug';

                $query->whereIn($queryColumn, $role);
            } else {
                $queryColumn = !is_null($column) ? $column : (is_numeric($role) ? 'roles.id' : 'roles.slug');

                $query->where($queryColumn, $role);
            }
        });
    }
778429
public static function getRoleId($role)
    {
        $map = [
            self::ENUM_ROLE_ADMIN => self::ENUM_ROLE_ADMIN_ID,
            self::ENUM_ROLE_USER  => self::ENUM_ROLE_USER_ID,
        ];

        // do not check if key exist deliberately. If wrong role is given it will cause an error.
        return $map[$role];
    }
767992
public function getRoles(string $role): array
    {
        if(!\in_array($role, $this->roles))
            throw new UndefinedRoleException("This role '{$role}' is not registered into RoleHierarchy");
        
        return isset($this->map[$role]) ? \array_merge([], [$role], $this->map[$role]) : [$role];
    }
639547
public function getRole($role) {
		
		if(false === is_string($role)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR);
		}

		foreach($this -> permissions as $type => $resources) {

			if($role === $type) {
				
				$p = new Resources();
				$p -> setResources($resources);

				return $p;
			}
		}

		return null;
	}