Commit a8cf0446 authored by Laurent Lécluse's avatar Laurent Lécluse
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
<?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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment