diff --git a/src/UnicaenAuth/Assertion/AbstractAssertion.php b/src/UnicaenAuth/Assertion/AbstractAssertion.php index 1236c6a3e10bafa078cb9a3a2c5109051fb8a5de..a0dd7c2cf395f8de8d144226b48d7737fc005e5a 100644 --- a/src/UnicaenAuth/Assertion/AbstractAssertion.php +++ b/src/UnicaenAuth/Assertion/AbstractAssertion.php @@ -3,11 +3,11 @@ namespace UnicaenAuth\Assertion; use BjyAuthorize\Service\Authorize; -use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; -use UnicaenApp\ServiceManager\ServiceLocatorAwareTrait; +use UnicaenAuth\Service\AuthorizeService; +use UnicaenAuth\Service\Traits\AuthorizeServiceAwareTrait; use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait; +use UnicaenAuth\Service\UserContext; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger; use Zend\Permissions\Acl\Acl; use Zend\Permissions\Acl\Assertion\AssertionInterface; use Zend\Permissions\Acl\Resource\ResourceInterface; @@ -18,10 +18,10 @@ use Zend\Permissions\Acl\Role\RoleInterface; * * @author Laurent LÉCLUSE */ -abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAwareInterface +abstract class AbstractAssertion implements AssertionInterface { - use ServiceLocatorAwareTrait; use UserContextServiceAwareTrait; + use AuthorizeServiceAwareTrait; /** * @var Acl @@ -34,9 +34,9 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw private $role = false; /** - * @var FlashMessenger + * @var MvcEvent */ - private $fm; + private $mvcEvent; @@ -117,9 +117,10 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw */ public function getAcl() { - if (!$this->acl){ + if (!$this->acl) { $this->acl = $this->getServiceAuthorize()->getAcl(); } + return $this->acl; } @@ -144,12 +145,13 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw */ public function getRole() { - if (false === $this->role){ - $sUserContext = $this->getServiceUserContext(); + if (false === $this->role) { + $sUserContext = $this->serviceUserContext; if ($sUserContext->getIdentity()) { $this->role = $sUserContext->getSelectedIdentityRole(); } } + return $this->role; } @@ -284,30 +286,26 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw */ protected function asserts($assertions) { - if (!is_array($assertions)){ + if (!is_array($assertions)) { $assertions = [$assertions]; } - foreach( $assertions as $assertion ){ + foreach ($assertions as $assertion) { if (!$assertion) return false; } return true; } - /** - * @var MvcEvent - */ - private $mvcEvent; - /** - * @param MvcEvent $mvcEvent - */ + public function setMvcEvent(MvcEvent $mvcEvent) { $this->mvcEvent = $mvcEvent; } + + /** * @return MvcEvent */ @@ -316,42 +314,4 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw return $this->mvcEvent; } - /** - * @var Authorize - */ - private $serviceAuthorize; - - /** - * @param Authorize $serviceAuthorize - */ - public function setServiceAuthorize(Authorize $serviceAuthorize) - { - $this->serviceAuthorize = $serviceAuthorize; - } - - /** - * @return Authorize - */ - private function getServiceAuthorize() - { - return $this->serviceAuthorize; - } - - /** - * @param FlashMessenger $fm - * @deprecated Merci d'abandonner cette méthode : SoC violation ! - */ - public function setFlashMessenger(FlashMessenger $fm) - { - $this->fm = $fm; - } - - /** - * @return FlashMessenger - * @deprecated Merci d'abandonner cette méthode : SoC violation ! - */ - protected function flashMessenger() - { - return $this->fm; - } } \ No newline at end of file diff --git a/src/UnicaenAuth/Assertion/AssertionFactory.php b/src/UnicaenAuth/Assertion/AssertionFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..77e68fc30b3f1df7e49d0ac3f345e08ed4a295ab --- /dev/null +++ b/src/UnicaenAuth/Assertion/AssertionFactory.php @@ -0,0 +1,44 @@ +get('Application'); + $mvcEvent = $application->getMvcEvent(); + + /* @var $serviceAuthorize Authorize */ + $serviceAuthorize = $container->get('BjyAuthorize\Service\Authorize'); + + /** @var UserContext $serviceUserContext */ + $serviceUserContext = $container->get('UnicaenAuth\Service\UserContext'); + + /* @var $assertion AbstractAssertion */ + $assertion = new $requestedName; + + $assertion->setMvcEvent($mvcEvent); + $assertion->setServiceAuthorize($serviceAuthorize); + $assertion->setServiceUserContext($serviceUserContext); + + return $assertion; + } +}