Skip to content
Snippets Groups Projects
Commit a8cf0446 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Création d'un trait (AuthorizeServiceTrait) pour pouvoir accéder au service...

Création d'un trait (AuthorizeServiceTrait) pour pouvoir accéder au service Authorize (pour faire $this->getServiceAuthorize->isAllowed par exemple)
parent f59f92b8
Branches
Tags
No related merge requests found
<?php
namespace UnicaenAuth\Service\Traits;
use UnicaenAuth\Service\AuthorizeService;
use RuntimeException;
/**
* Description of AuthorizeServiceAwareTrait
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
trait AuthorizeServiceAwareTrait
{
/**
* @var AuthorizeService
*/
private $serviceAuthorize;
/**
* @param AuthorizeService $serviceAuthorize
*
* @return self
*/
public function setServiceAuthorize(AuthorizeService $serviceAuthorize)
{
$this->serviceAuthorize = $serviceAuthorize;
return $this;
}
/**
* @return AuthorizeService
* @throws RuntimeException
*/
public function getServiceAuthorize()
{
if (empty($this->serviceAuthorize)) {
if (!method_exists($this, 'getServiceLocator')) {
throw new RuntimeException('La classe ' . get_class($this) . ' n\'a pas accès au ServiceLocator.');
}
$serviceLocator = $this->getServiceLocator();
if (method_exists($serviceLocator, 'getServiceLocator')) {
$serviceLocator = $serviceLocator->getServiceLocator();
}
$this->serviceAuthorize = $serviceLocator->get('BjyAuthorize\Service\Authorize');
}
return $this->serviceAuthorize;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment