Created
March 5, 2015 16:29
-
-
Save acelaya/32ec3da93eae81bb2354 to your computer and use it in GitHub Desktop.
Role provider example
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 | |
return [ | |
'TrascastroACL' => [ | |
// [...] | |
'role_provider' => 'Application\Provider\MyRoleProvider', | |
], | |
]; |
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 | |
namespace Application\Provider; | |
use TrascastroACL\Provider\RoleProviderInterface; | |
use Zend\Authentication\AuthenticationServiceInterface; | |
use Application\Entity\User; | |
class MyRoleProvider implements RoleProviderInterface | |
{ | |
private $authService; | |
public function __construct(AuthenticationServiceInterface $authService) | |
{ | |
$this->authService = $authService; | |
} | |
/** | |
* @return string | |
*/ | |
public function getCurrentUserRoleName() | |
{ | |
if (! $this->authService->hasIdentity()) { | |
return 'guest'; | |
} | |
/** @var User $currentUser */ | |
$currentUser = $this->authService->getIdentity(); | |
return $currentUser->getRole()->getName(); | |
} | |
} |
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 | |
namespace TrascastroACL\Provider; | |
interface RoleProviderInterface | |
{ | |
/** | |
* @return string | |
*/ | |
public function getCurrentUserRoleName(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment