diff --git a/src/UnicaenLdap/Entity/Group.php b/src/UnicaenLdap/Entity/Group.php index 23a68d0a97efe2a49e2e904c0aec747454955a7b..84dccb263276f4fabb02cca18f37e2bd8c846243 100644 --- a/src/UnicaenLdap/Entity/Group.php +++ b/src/UnicaenLdap/Entity/Group.php @@ -67,11 +67,11 @@ class Group extends Entity */ public function getPeople($orderBy = null) { - /* @var $people \UnicaenLdap\Service\People */ - $people = $this->getService()->getLdapServiceForEntityClass(\UnicaenLdap\Service\People::class); + /* @var $peopleService \UnicaenLdap\Service\People */ + $peopleService = $this->getService()->getLdapPeopleService(); /** @var People[] $result */ - $result = $people->getAllBy($this->get('member'), 'dn', $orderBy); + $result = $peopleService->getAllBy($this->get('member'), 'dn', $orderBy); return $result; } diff --git a/src/UnicaenLdap/Entity/People.php b/src/UnicaenLdap/Entity/People.php index a7f36aae636c958e97217859d4ec14bfe598df8f..d647ee75a3333caa16549fa987b4832aa77a4d6c 100644 --- a/src/UnicaenLdap/Entity/People.php +++ b/src/UnicaenLdap/Entity/People.php @@ -133,9 +133,9 @@ class People extends Entity */ public function getGroups(DateTime $dateObservation = null, $orderBy = null) { - $group = $this->getService()->getLdapServiceForEntityClass(\UnicaenLdap\Service\Group::class); + $groupService = $this->getService()->getLdapGroupService(); - return $group->filterValids($group->getAllBy($this->get('memberOf'), 'dn', $orderBy), $dateObservation); + return $groupService->filterValids($groupService->getAllBy($this->get('memberOf'), 'dn', $orderBy), $dateObservation); } /** @@ -168,67 +168,50 @@ class People extends Entity return 0 === strpos($this->uid, 'i'); } - /** - * @var \UnicaenLdap\Service\Structure - */ - protected $ldapStructureService; - - /** - * @return \UnicaenLdap\Service\Structure - */ - protected function getLdapStructureService() - { - if (null === $this->ldapStructureService) { - $this->ldapStructureService = - $this->getService()->getLdapServiceForEntityClass(\UnicaenLdap\Service\Structure::class); - } - - return $this->ldapStructureService; - } - /** * Retourne les structures auxquelles appartiennent la personne * - * @return Structure[] + * @return Entity[]|Structure[] */ public function getEduPersonOrgUnit() { - $structure = $this->getLdapStructureService(); + $structureService = $this->getService()->getLdapStructureService(); $dn = $this->eduPersonOrgUnitDN; if (empty($dn)) return null; - return $structure->getAllBy($dn, 'dn'); + return $structureService->getAllBy($dn, 'dn'); } /** * Retourne la structure principale à laquelle appartient la personne * - * @return Structure + * @return Entity|Structure + * @throws \UnicaenLdap\Exception */ public function getEduPersonPrimaryOrgUnit() { - $structure = $this->getLdapStructureService(); + $structureService = $this->getService()->getLdapStructureService(); $dn = $this->eduPersonPrimaryOrgUnitDN; if (empty($dn)) return null; - return $structure->getBy($dn, 'dn'); + return $structureService->getBy($dn, 'dn'); } /** * Retourne la structure d'affectation de la personne * * @todo à terminer - * @return Structure[] + * @return Entity|Structure * @throws \Exception */ public function getEntiteAffectation() { throw new \Exception('Méthode pas finie'); - $structure = $this->getLdapStructureService(); + $structureService = $this->getService()->getLdapStructureService(); $codes = $this->getNode()->getAttribute('supannEntiteAffectation'); var_dump($codes); - return $structure->getBy($dn, 'dn'); + return $structureService->getBy($dn, 'dn'); } /** @@ -241,7 +224,7 @@ class People extends Entity public function getEntiteAffectationPrincipale() { throw new \Exception('Méthode pas finie'); - $structure = $this->getLdapStructureService(); + $structureService = $this->getService()->getLdapStructureService(); $codes = []; $affectations = $this->getNode()->getAttribute('supannAffectation'); @@ -251,7 +234,7 @@ class People extends Entity $code = $this->supannAffectation; if (empty($dn)) return null; - return $structure->getBy($dn, 'dn'); + return $structureService->getBy($dn, 'dn'); } /** @@ -264,13 +247,13 @@ class People extends Entity public function getAffectationDescription() { throw new \Exception('Méthode pas finie'); - $structure = $this->getLdapStructureService(); + $structureService = $this->getService()->getLdapStructureService(); list($code, $description) = explode(';', $this->supannAffectation); $code = $this->supannAffectation; if (empty($dn)) return null; - return $structure->getBy($dn, 'dn'); + return $structureService->getBy($dn, 'dn'); } /** diff --git a/src/UnicaenLdap/Service/AbstractService.php b/src/UnicaenLdap/Service/AbstractService.php index 346aaf91bc9c9be1b21210e9f724ef7fac21dfea..9a4ed90c3e17a5a7ff95f03c1b224ee91249362b 100644 --- a/src/UnicaenLdap/Service/AbstractService.php +++ b/src/UnicaenLdap/Service/AbstractService.php @@ -17,8 +17,19 @@ use Zend\Stdlib\ErrorHandler; * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ -abstract class AbstractService +abstract class AbstractService implements + LdapPeopleServiceAwareInterface, + LdapStructureServiceAwareInterface, + LdapGroupServiceAwareInterface, + LdapSystemServiceAwareInterface, + LdapGenericServiceAwareInterface { + use LdapPeopleServiceAwareTrait; + use LdapStructureServiceAwareTrait; + use LdapGroupServiceAwareTrait; + use LdapSystemServiceAwareTrait; + use LdapGenericServiceAwareTrait; + /** * Limite de recherche par défaut */ @@ -53,37 +64,6 @@ abstract class AbstractService */ protected $count; - /** - * @var array - */ - protected $ldapServicesByEntityClass = [ - \UnicaenLdap\Entity\People::class => null, - \UnicaenLdap\Entity\Structure::class => null, - \UnicaenLdap\Entity\System::class => null, - \UnicaenLdap\Entity\Group::class => null, - \UnicaenLdap\Entity\Generic::class => null, - ]; - - /** - * @param array - */ - public function setLdapServicesByEntityClass(array $ldapServicesByEntityClass) - { - $this->ldapServicesByEntityClass = $ldapServicesByEntityClass; - } - - /** - * @param string $entityClass - * @return mixed - */ - public function getLdapServiceForEntityClass($entityClass) - { - if (! isset($this->ldapServicesByEntityClass[$entityClass])) { - throw new RuntimeException("Le service de recherche LDAP pour la classe d'entité $entityClass n'a pas été injecté."); - } - - return $this->ldapServicesByEntityClass[$entityClass]; - } /** * Retourne le type du service diff --git a/src/UnicaenLdap/Service/GenericFactory.php b/src/UnicaenLdap/Service/GenericFactory.php index d91a7111142f10678d2147825bed8cf62e9c25cd..a3e2a7d243d4597d4260746d05e0a0b6e7d7820b 100644 --- a/src/UnicaenLdap/Service/GenericFactory.php +++ b/src/UnicaenLdap/Service/GenericFactory.php @@ -3,14 +3,11 @@ namespace UnicaenLdap\Service; use Interop\Container\ContainerInterface; +use UnicaenLdap\Ldap; +use UnicaenLdap\Service; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -/** - * - * - * @author Unicaen - */ class GenericFactory implements FactoryInterface { public function createService(ServiceLocatorInterface $serviceLocator) @@ -18,22 +15,35 @@ class GenericFactory implements FactoryInterface return $this->__invoke($serviceLocator, '?'); } + /** + * Create service + * + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options + * @return object|Generic + */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $service = new Generic(); - - /** @var \UnicaenLdap\Ldap $ldap */ + /** + * @var Ldap $ldap + * @var Service\People $ldapPeopleService + * @var Service\Structure $ldapStructureService + * @var Service\Group $ldapGroupService + * @var Service\System $ldapSystemService + */ $ldap = $container->get('ldap'); + $ldapPeopleService = $container->get('ldapServicePeople'); + $ldapStructureService = $container->get('ldapServiceStructure'); + $ldapGroupService = $container->get('ldapServiceGroup'); + $ldapSystemService = $container->get('ldapServiceSystem'); + $service = new Generic(); $service->setLdap($ldap); - - $service->setLdapServicesByEntityClass([ - \UnicaenLdap\Entity\People::class => $container->get('ldapServicePeople'), - \UnicaenLdap\Entity\Structure::class => $container->get('ldapServiceStructure'), - \UnicaenLdap\Entity\System::class => $container->get('ldapServiceSystem'), - \UnicaenLdap\Entity\Group::class => $container->get('ldapServiceGroup'), -// \UnicaenLdap\Entity\Generic::class => $container->get('ldapServiceGeneric'), - ]); + $service->setLdapPeopleService($ldapPeopleService); + $service->setLdapStructureService($ldapStructureService); + $service->setLdapGroupService($ldapGroupService); + $service->setLdapSystemService($ldapSystemService); return $service; } diff --git a/src/UnicaenLdap/Service/GroupFactory.php b/src/UnicaenLdap/Service/GroupFactory.php index eaa3871b5186122fe6d888b99bd2a43769e3b08e..4966a39f1317d9fcb61f043ceb05b6456ca3f801 100644 --- a/src/UnicaenLdap/Service/GroupFactory.php +++ b/src/UnicaenLdap/Service/GroupFactory.php @@ -3,14 +3,11 @@ namespace UnicaenLdap\Service; use Interop\Container\ContainerInterface; +use UnicaenLdap\Ldap; +use UnicaenLdap\Service; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -/** - * - * - * @author Unicaen - */ class GroupFactory implements FactoryInterface { public function createService(ServiceLocatorInterface $serviceLocator) @@ -18,22 +15,35 @@ class GroupFactory implements FactoryInterface return $this->__invoke($serviceLocator, '?'); } + /** + * Create service + * + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options + * @return object|Group + */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $service = new Group(); - - /** @var \UnicaenLdap\Ldap $ldap */ + /** + * @var Ldap $ldap + * @var Service\People $ldapPeopleService + * @var Service\Structure $ldapStructureService + * @var Service\System $ldapSystemService + * @var Service\Generic $ldapGenericService + */ $ldap = $container->get('ldap'); + $ldapPeopleService = $container->get('ldapServicePeople'); + $ldapStructureService = $container->get('ldapServiceStructure'); + $ldapSystemService = $container->get('ldapServiceSystem'); + $ldapGenericService = $container->get('ldapServiceGeneric'); + $service = new Group(); $service->setLdap($ldap); - - $service->setLdapServicesByEntityClass([ - \UnicaenLdap\Entity\People::class => $container->get('ldapServicePeople'), - \UnicaenLdap\Entity\Structure::class => $container->get('ldapServiceStructure'), - \UnicaenLdap\Entity\System::class => $container->get('ldapServiceSystem'), -// \UnicaenLdap\Entity\Group::class => $container->get('ldapServiceGroup'), - \UnicaenLdap\Entity\Generic::class => $container->get('ldapServiceGeneric'), - ]); + $service->setLdapPeopleService($ldapPeopleService); + $service->setLdapStructureService($ldapStructureService); + $service->setLdapSystemService($ldapSystemService); + $service->setLdapGenericService($ldapGenericService); return $service; } diff --git a/src/UnicaenLdap/Service/LdapGenericServiceAwareInterface.php b/src/UnicaenLdap/Service/LdapGenericServiceAwareInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..96fa02cd422a23457b7902541a5ee640acc2c68c --- /dev/null +++ b/src/UnicaenLdap/Service/LdapGenericServiceAwareInterface.php @@ -0,0 +1,19 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\Generic as LdapGenericService; + +interface LdapGenericServiceAwareInterface +{ + /** + * @param LdapGenericService $ldapGenericService + * @return mixed + */ + public function setLdapGenericService(LdapGenericService $ldapGenericService); + + /** + * @return LdapGenericService + */ + public function getLdapGenericService(); +} diff --git a/src/UnicaenLdap/Service/LdapGenericServiceAwareTrait.php b/src/UnicaenLdap/Service/LdapGenericServiceAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..c4f1646d5a691cf5541a216febb85aae6ebf8021 --- /dev/null +++ b/src/UnicaenLdap/Service/LdapGenericServiceAwareTrait.php @@ -0,0 +1,29 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\Generic as LdapGenericService; + +trait LdapGenericServiceAwareTrait +{ + /** + * @var LdapGenericService + */ + protected $ldapGenericService; + + /** + * @param LdapGenericService $ldapGenericService + */ + public function setLdapGenericService(LdapGenericService $ldapGenericService) + { + $this->ldapGenericService = $ldapGenericService; + } + + /** + * @return LdapGenericService + */ + public function getLdapGenericService() + { + return $this->ldapGenericService; + } +} \ No newline at end of file diff --git a/src/UnicaenLdap/Service/LdapGroupServiceAwareInterface.php b/src/UnicaenLdap/Service/LdapGroupServiceAwareInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..a438d0f075d99f1bf8cd2f25d9121c469b0e0961 --- /dev/null +++ b/src/UnicaenLdap/Service/LdapGroupServiceAwareInterface.php @@ -0,0 +1,19 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\Group as LdapGroupService; + +interface LdapGroupServiceAwareInterface +{ + /** + * @param LdapGroupService $ldapGroupService + * @return mixed + */ + public function setLdapGroupService(LdapGroupService $ldapGroupService); + + /** + * @return LdapGroupService + */ + public function getLdapGroupService(); +} diff --git a/src/UnicaenLdap/Service/LdapGroupServiceAwareTrait.php b/src/UnicaenLdap/Service/LdapGroupServiceAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..d6bb16355ead97b35e48553e36ba2d4d585367f0 --- /dev/null +++ b/src/UnicaenLdap/Service/LdapGroupServiceAwareTrait.php @@ -0,0 +1,29 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\Group as LdapGroupService; + +trait LdapGroupServiceAwareTrait +{ + /** + * @var LdapGroupService + */ + protected $ldapGroupService; + + /** + * @param LdapGroupService $ldapGroupService + */ + public function setLdapGroupService(LdapGroupService $ldapGroupService) + { + $this->ldapGroupService = $ldapGroupService; + } + + /** + * @return LdapGroupService + */ + public function getLdapGroupService() + { + return $this->ldapGroupService; + } +} \ No newline at end of file diff --git a/src/UnicaenLdap/Service/LdapPeopleServiceAwareInterface.php b/src/UnicaenLdap/Service/LdapPeopleServiceAwareInterface.php index 40e8f85a5236a6b95a5e6f878917eafd263d2f15..c08423e5ef66489043ab4ed109ae66a495df2b7a 100644 --- a/src/UnicaenLdap/Service/LdapPeopleServiceAwareInterface.php +++ b/src/UnicaenLdap/Service/LdapPeopleServiceAwareInterface.php @@ -6,5 +6,14 @@ use UnicaenLdap\Service\People as LdapPeopleService; interface LdapPeopleServiceAwareInterface { + /** + * @param LdapPeopleService $ldapPeopleService + * @return mixed + */ public function setLdapPeopleService(LdapPeopleService $ldapPeopleService); -} \ No newline at end of file + + /** + * @return LdapPeopleService + */ + public function getLdapPeopleService(); +} diff --git a/src/UnicaenLdap/Service/LdapPeopleServiceAwareTrait.php b/src/UnicaenLdap/Service/LdapPeopleServiceAwareTrait.php index f54468221144c9bc6c35d25ec6613fa775b97f5b..dd694622f3305f9588b9642f3ed07450842e4833 100644 --- a/src/UnicaenLdap/Service/LdapPeopleServiceAwareTrait.php +++ b/src/UnicaenLdap/Service/LdapPeopleServiceAwareTrait.php @@ -18,4 +18,12 @@ trait LdapPeopleServiceAwareTrait { $this->ldapPeopleService = $ldapPeopleService; } + + /** + * @return LdapPeopleService + */ + public function getLdapPeopleService() + { + return $this->ldapPeopleService; + } } \ No newline at end of file diff --git a/src/UnicaenLdap/Service/LdapStructureServiceAwareInterface.php b/src/UnicaenLdap/Service/LdapStructureServiceAwareInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..1ce386a6dc7f2942de821c437e876b0e85625051 --- /dev/null +++ b/src/UnicaenLdap/Service/LdapStructureServiceAwareInterface.php @@ -0,0 +1,19 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\Structure as LdapStructureService; + +interface LdapStructureServiceAwareInterface +{ + /** + * @param LdapStructureService $ldapStructureService + * @return mixed + */ + public function setLdapStructureService(LdapStructureService $ldapStructureService); + + /** + * @return LdapStructureService + */ + public function getLdapStructureService(); +} diff --git a/src/UnicaenLdap/Service/LdapStructureServiceAwareTrait.php b/src/UnicaenLdap/Service/LdapStructureServiceAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..f8d4c20a3b32776b8a43563ec2d897120ec6c774 --- /dev/null +++ b/src/UnicaenLdap/Service/LdapStructureServiceAwareTrait.php @@ -0,0 +1,29 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\Structure as LdapStructureService; + +trait LdapStructureServiceAwareTrait +{ + /** + * @var LdapStructureService + */ + protected $ldapStructureService; + + /** + * @param LdapStructureService $ldapStructureService + */ + public function setLdapStructureService(LdapStructureService $ldapStructureService) + { + $this->ldapStructureService = $ldapStructureService; + } + + /** + * @return LdapStructureService + */ + public function getLdapStructureService() + { + return $this->ldapStructureService; + } +} \ No newline at end of file diff --git a/src/UnicaenLdap/Service/LdapSystemServiceAwareInterface.php b/src/UnicaenLdap/Service/LdapSystemServiceAwareInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..d6c6efa85c2ceceae6d64264788be30ee924c315 --- /dev/null +++ b/src/UnicaenLdap/Service/LdapSystemServiceAwareInterface.php @@ -0,0 +1,19 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\System as LdapSystemService; + +interface LdapSystemServiceAwareInterface +{ + /** + * @param LdapSystemService $ldapSystemService + * @return mixed + */ + public function setLdapSystemService(LdapSystemService $ldapSystemService); + + /** + * @return LdapSystemService + */ + public function getLdapSystemService(); +} diff --git a/src/UnicaenLdap/Service/LdapSystemServiceAwareTrait.php b/src/UnicaenLdap/Service/LdapSystemServiceAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..6b86710329f2fecf968304a3660d5c19a1ae4645 --- /dev/null +++ b/src/UnicaenLdap/Service/LdapSystemServiceAwareTrait.php @@ -0,0 +1,29 @@ +<?php + +namespace UnicaenLdap\Service; + +use UnicaenLdap\Service\System as LdapSystemService; + +trait LdapSystemServiceAwareTrait +{ + /** + * @var LdapSystemService + */ + protected $ldapSystemService; + + /** + * @param LdapSystemService $ldapSystemService + */ + public function setLdapSystemService(LdapSystemService $ldapSystemService) + { + $this->ldapSystemService = $ldapSystemService; + } + + /** + * @return LdapSystemService + */ + public function getLdapSystemService() + { + return $this->ldapSystemService; + } +} \ No newline at end of file diff --git a/src/UnicaenLdap/Service/PeopleFactory.php b/src/UnicaenLdap/Service/PeopleFactory.php index 485f02ab0a530e723e6b71d2d06e5db2a8f1cb1d..b1de6d368f346bf567d326ace635ef0fa41276aa 100644 --- a/src/UnicaenLdap/Service/PeopleFactory.php +++ b/src/UnicaenLdap/Service/PeopleFactory.php @@ -3,6 +3,8 @@ namespace UnicaenLdap\Service; use Interop\Container\ContainerInterface; +use UnicaenLdap\Ldap; +use UnicaenLdap\Service; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -18,22 +20,35 @@ class PeopleFactory implements FactoryInterface return $this->__invoke($serviceLocator, '?'); } + /** + * Create service + * + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options + * @return object|People + */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $service = new People(); - - /** @var \UnicaenLdap\Ldap $ldap */ + /** + * @var Ldap $ldap + * @var Service\Structure $ldapStructureService + * @var Service\Group $ldapGroupService + * @var Service\System $ldapSystemService + * @var Service\Generic $ldapGenericService + */ $ldap = $container->get('ldap'); + $ldapStructureService = $container->get('ldapServiceStructure'); + $ldapGroupService = $container->get('ldapServiceGroup'); + $ldapSystemService = $container->get('ldapServiceSystem'); + $ldapGenericService = $container->get('ldapServiceGeneric'); + $service = new People(); $service->setLdap($ldap); - - $service->setLdapServicesByEntityClass([ -// \UnicaenLdap\Entity\People::class => $container->get('ldapServicePeople'), - \UnicaenLdap\Entity\Structure::class => $container->get('ldapServiceStructure'), - \UnicaenLdap\Entity\System::class => $container->get('ldapServiceSystem'), - \UnicaenLdap\Entity\Group::class => $container->get('ldapServiceGroup'), - \UnicaenLdap\Entity\Generic::class => $container->get('ldapServiceGeneric'), - ]); + $service->setLdapStructureService($ldapStructureService); + $service->setLdapGroupService($ldapGroupService); + $service->setLdapSystemService($ldapSystemService); + $service->setLdapGenericService($ldapGenericService); return $service; } diff --git a/src/UnicaenLdap/Service/StructureFactory.php b/src/UnicaenLdap/Service/StructureFactory.php index 33cd58adc86d83dc44981d5993169e7ff5248080..7759770f09479d5130bd90bc1edefe42f9dfa54b 100644 --- a/src/UnicaenLdap/Service/StructureFactory.php +++ b/src/UnicaenLdap/Service/StructureFactory.php @@ -3,6 +3,8 @@ namespace UnicaenLdap\Service; use Interop\Container\ContainerInterface; +use UnicaenLdap\Ldap; +use UnicaenLdap\Service; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -18,22 +20,35 @@ class StructureFactory implements FactoryInterface return $this->__invoke($serviceLocator, '?'); } + /** + * Create service + * + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options + * @return object|Structure + */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $service = new Structure(); - - /** @var \UnicaenLdap\Ldap $ldap */ + /** + * @var Ldap $ldap + * @var Service\People $ldapPeopleService + * @var Service\Group $ldapGroupService + * @var Service\System $ldapSystemService + * @var Service\Generic $ldapGenericService + */ $ldap = $container->get('ldap'); + $ldapPeopleService = $container->get('ldapServicePeople'); + $ldapGroupService = $container->get('ldapServiceGroup'); + $ldapSystemService = $container->get('ldapServiceSystem'); + $ldapGenericService = $container->get('ldapServiceGeneric'); + $service = new Structure(); $service->setLdap($ldap); - - $service->setLdapServicesByEntityClass([ - \UnicaenLdap\Entity\People::class => $container->get('ldapServicePeople'), -// \UnicaenLdap\Entity\Structure::class => $container->get('ldapServiceStructure'), - \UnicaenLdap\Entity\System::class => $container->get('ldapServiceSystem'), - \UnicaenLdap\Entity\Group::class => $container->get('ldapServiceGroup'), - \UnicaenLdap\Entity\Generic::class => $container->get('ldapServiceGeneric'), - ]); + $service->setLdapPeopleService($ldapPeopleService); + $service->setLdapGroupService($ldapGroupService); + $service->setLdapSystemService($ldapSystemService); + $service->setLdapGenericService($ldapGenericService); return $service; } diff --git a/src/UnicaenLdap/Service/SystemFactory.php b/src/UnicaenLdap/Service/SystemFactory.php index 9d036e728cf43e6600ff28c10e385708adac3cd2..73953d8d7534440506ccac06b98418db92ddf187 100644 --- a/src/UnicaenLdap/Service/SystemFactory.php +++ b/src/UnicaenLdap/Service/SystemFactory.php @@ -3,6 +3,8 @@ namespace UnicaenLdap\Service; use Interop\Container\ContainerInterface; +use UnicaenLdap\Ldap; +use UnicaenLdap\Service; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -18,22 +20,35 @@ class SystemFactory implements FactoryInterface return $this->__invoke($serviceLocator, '?'); } + /** + * Create service + * + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options + * @return object|System + */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $service = new System(); - - /** @var \UnicaenLdap\Ldap $ldap */ + /** + * @var Ldap $ldap + * @var Service\People $ldapPeopleService + * @var Service\Structure $ldapStructureService + * @var Service\Group $ldapGroupService + * @var Service\Generic $ldapGenericService + */ $ldap = $container->get('ldap'); + $ldapPeopleService = $container->get('ldapServicePeople'); + $ldapStructureService = $container->get('ldapServiceStructure'); + $ldapGroupService = $container->get('ldapServiceGroup'); + $ldapGenericService = $container->get('ldapServiceGeneric'); + $service = new System(); $service->setLdap($ldap); - - $service->setLdapServicesByEntityClass([ - \UnicaenLdap\Entity\People::class => $container->get('ldapServicePeople'), - \UnicaenLdap\Entity\Structure::class => $container->get('ldapServiceStructure'), -// \UnicaenLdap\Entity\System::class => $container->get('ldapServiceSystem'), - \UnicaenLdap\Entity\Group::class => $container->get('ldapServiceGroup'), - \UnicaenLdap\Entity\Generic::class => $container->get('ldapServiceGeneric'), - ]); + $service->setLdapPeopleService($ldapPeopleService); + $service->setLdapStructureService($ldapStructureService); + $service->setLdapGroupService($ldapGroupService); + $service->setLdapGenericService($ldapGenericService); return $service; }