Improved readability of privilege error messages

This commit is contained in:
Marcin Kurczewski 2014-10-15 21:20:13 +02:00
parent c60e8e1b9f
commit 231d6a732f

View file

@ -48,7 +48,7 @@ class PrivilegeService
public function assertPrivilege($privilege) public function assertPrivilege($privilege)
{ {
if (!$this->hasPrivilege($privilege)) if (!$this->hasPrivilege($privilege))
$this->fail(); $this->fail($privilege);
} }
public function assertLoggedIn($userIdentifier = null) public function assertLoggedIn($userIdentifier = null)
@ -56,12 +56,12 @@ class PrivilegeService
if ($userIdentifier) if ($userIdentifier)
{ {
if (!$this->isLoggedIn($userIdentifier)) if (!$this->isLoggedIn($userIdentifier))
$this->fail(); $this->fail('not logged in');
} }
else else
{ {
if (!$this->authService->isLoggedIn()) if (!$this->authService->isLoggedIn())
$this->fail(); $this->fail('not logged in');
} }
} }
@ -87,8 +87,8 @@ class PrivilegeService
} }
} }
private function fail() private function fail($reason)
{ {
throw new \DomainException('Unprivileged operation'); throw new \DomainException('Unprivileged operation' . ($reason ? ' (' . $reason . ')' : ''));
} }
} }