public function __call($method, $parameters)
{
$methods = $this->getUserMethods();
if (in_array($method, $methods)) {
$users = $this->getUserRepository();
return call_user_func_array([$users, $method], $parameters);
}
if (starts_with($method, 'findUserBy')) {
$user = $this->getUserRepository();
$method = 'findBy' . substr($method, 10);
return call_user_func_array([$user, $method], $parameters);
}
if (starts_with($method, 'findRoleBy')) {
$roles = $this->getRoleRepository();
$method = 'findBy' . substr($method, 10);
return call_user_func_array([$roles, $method], $parameters);
}
$methods = ['getRoles', 'inRole', 'hasAccess', 'hasAnyAccess'];
$className = get_class($this);
if (in_array($method, $methods)) {
$user = $this->getUser();
if ($user === null) {
throw new BadMethodCallException("Method {$className}::{$method}() can only be called if a user is logged in.");
}
return call_user_func_array([$user, $method], $parameters);
}
throw new BadMethodCallException("Call to undefined method {$className}::{$method}()");
}