Skip to content

Instantly share code, notes, and snippets.

@acelaya
Created March 5, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acelaya/32ec3da93eae81bb2354 to your computer and use it in GitHub Desktop.
Save acelaya/32ec3da93eae81bb2354 to your computer and use it in GitHub Desktop.
Role provider example
<?php
return [
'TrascastroACL' => [
// [...]
'role_provider' => 'Application\Provider\MyRoleProvider',
],
];
<?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();
}
}
<?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