Commit 0482d4d4 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge branch 'zf-3.x'

parents 78275982 2dca4963
.idea
vendor
\ No newline at end of file
......@@ -3,17 +3,17 @@
"description": "Module Ldap des applications Unicaen",
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-servicemanager": "~2.4 || ^2.7",
"zendframework/zend-modulemanager": "~2.4 || ^2.7",
"zendframework/zend-config": "~2.4 || ^2.7",
"zendframework/zend-serializer": "~2.4 || ^2.7",
"zendframework/zend-log": "~2.4 || ^2.7",
"zendframework/zend-i18n": "~2.4 || ^2.7",
"zendframework/zend-stdlib": "~2.4 || ^2.7",
"zendframework/zend-ldap": "~2.4 || ^2.7"
"zendframework/zend-config": "^3.2",
"zendframework/zend-i18n": "^2.9",
"zendframework/zend-ldap": "^2.10",
"zendframework/zend-log": "^2.10",
"zendframework/zend-modulemanager": "^2.8",
"zendframework/zend-serializer": "^2.9",
"zendframework/zend-servicemanager": "^3.4",
"zendframework/zend-stdlib": "^3.2"
},
"require-dev": {
"phpunit/PHPUnit": ">=3.7",
"phpunit/phpunit": ">=3.7",
"zendframework/zend-test": ">=2.2"
},
"autoload": {
......
<?php
use UnicaenLdap\LdapFactory;
namespace UnicaenLdap;
use UnicaenLdap\Entity\Generic;
use UnicaenLdap\Entity\Group;
use UnicaenLdap\Entity\People;
use UnicaenLdap\Entity\Structure;
use UnicaenLdap\Entity\System;
use UnicaenLdap\Options\ModuleOptionsFactory;
use UnicaenLdap\Service\Generic as LdapGenericService;
use UnicaenLdap\Service\GenericFactory as GenericServiceFactory;
use UnicaenLdap\Service\Group as LdapGroupService;
use UnicaenLdap\Service\GroupFactory as GroupServiceFactory;
use UnicaenLdap\Service\People as LdapPeopleService;
use UnicaenLdap\Service\PeopleFactory as PeopleServiceFactory;
use UnicaenLdap\Service\Structure as LdapStructureService;
use UnicaenLdap\Service\StructureFactory as StructureServiceFactory;
use UnicaenLdap\Service\System as LdapSystemService;
use UnicaenLdap\Service\SystemFactory as SystemServiceFactory;
use Zend\ServiceManager\Proxy\LazyServiceFactory;
;;
return array(
'unicaen-ldap' => [
......@@ -23,5 +37,48 @@ return array(
'LdapServiceStructure' => StructureServiceFactory::class,
'LdapServiceSystem' => SystemServiceFactory::class,
],
'aliases' => [
'ldap' => 'Ldap',
'ldapOptions' => 'LdapOptions',
'ldapServiceGeneric' => 'LdapServiceGeneric',
'ldapServiceGroup' => 'LdapServiceGroup',
'ldapServicePeople' => 'LdapServicePeople',
'ldapServiceStructure' => 'LdapServiceStructure',
'ldapServiceSystem' => 'LdapServiceSystem',
LdapGenericService::class => 'LdapServiceGeneric',
LdapPeopleService::class => 'LdapServicePeople',
LdapGroupService ::class => 'LdapServiceGroup',
LdapStructureService::class => 'LdapServiceStructure',
LdapSystemService::class => 'LdapServiceSystem',
],
'lazy_services' => [
// Mapping services to their class names is required since the ServiceManager is not a declarative DIC.
'class_map' => [
'LdapServicePeople' => LdapPeopleService::class,
'LdapServiceGeneric' => LdapGenericService::class,
'LdapServiceGroup' => LdapGroupService::class,
'LdapServiceStructure' => LdapStructureService::class,
'LdapServiceSystem' => LdapSystemService::class,
],
],
'delegators' => [
'LdapServicePeople' => [
LazyServiceFactory::class,
],
'LdapServiceGeneric' => [
LazyServiceFactory::class,
],
'LdapServiceGroup' => [
LazyServiceFactory::class,
],
'LdapServiceStructure' => [
LazyServiceFactory::class,
],
'LdapServiceSystem' => [
LazyServiceFactory::class,
],
],
],
);
......@@ -67,11 +67,11 @@ class Group extends Entity
*/
public function getPeople($orderBy = null)
{
/* @var $people \UnicaenLdap\Service\People */
$people = $this->getService()->getServiceLocator()->get('ldapServicePeople');
/* @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;
}
......
......@@ -133,9 +133,9 @@ class People extends Entity
*/
public function getGroups(DateTime $dateObservation = null, $orderBy = null)
{
$group = $this->getService()->getServiceLocator()->get('ldapServiceGroup');
$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);
}
/**
......@@ -171,46 +171,47 @@ class People extends Entity
/**
* Retourne les structures auxquelles appartiennent la personne
*
* @return Structure[]
* @return Entity[]|Structure[]
*/
public function getEduPersonOrgUnit()
{
$structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
$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->getService()->getServiceLocator()->get('ldapServiceStructure');
$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->getService()->getServiceLocator()->get('ldapServiceStructure');
$structureService = $this->getService()->getLdapStructureService();
$codes = $this->getNode()->getAttribute('supannEntiteAffectation');
var_dump($codes);
return $structure->getBy($dn, 'dn');
return $structureService->getBy($dn, 'dn');
}
/**
......@@ -223,7 +224,7 @@ class People extends Entity
public function getEntiteAffectationPrincipale()
{
throw new \Exception('Méthode pas finie');
$structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
$structureService = $this->getService()->getLdapStructureService();
$codes = [];
$affectations = $this->getNode()->getAttribute('supannAffectation');
......@@ -233,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');
}
/**
......@@ -246,13 +247,13 @@ class People extends Entity
public function getAffectationDescription()
{
throw new \Exception('Méthode pas finie');
$structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
$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');
}
/**
......
......@@ -2,6 +2,7 @@
namespace UnicaenLdap;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -12,16 +13,15 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class LdapFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return Ldap
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var $options \UnicaenLdap\Options\ModuleOptions */
$options = $serviceLocator->get('ldapOptions');
$options = $container->get('ldapOptions');
return new Ldap( $options->getLdap() );
}
......
......@@ -2,6 +2,7 @@
namespace UnicaenLdap\Options;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -12,15 +13,14 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class ModuleOptionsFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return ModuleOptions
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Configuration');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('Configuration');
$moduleConfig = isset($config['unicaen-ldap']) ? $config['unicaen-ldap'] : array();
return new ModuleOptions($moduleConfig);
......
......@@ -2,16 +2,14 @@
namespace UnicaenLdap\Service;
use UnicaenLdap\Ldap;
use UnicaenApp\Exception\RuntimeException;
use UnicaenLdap\Collection;
use UnicaenLdap\Entity\Entity;
use UnicaenLdap\Exception;
use UnicaenLdap\Collection;
use UnicaenLdap\Filter\Filter;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\Ldap\Filter\AbstractFilter;
use UnicaenLdap\Ldap;
use Zend\Ldap\Dn;
use Zend\Ldap\Filter\AbstractFilter;
use Zend\Stdlib\ErrorHandler;
/**
......@@ -19,9 +17,18 @@ 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 ServiceLocatorAwareTrait;
use LdapPeopleServiceAwareTrait;
use LdapStructureServiceAwareTrait;
use LdapGroupServiceAwareTrait;
use LdapSystemServiceAwareTrait;
use LdapGenericServiceAwareTrait;
/**
* Limite de recherche par défaut
......@@ -57,6 +64,7 @@ abstract class AbstractService
*/
protected $count;
/**
* Retourne le type du service
*
......@@ -74,9 +82,6 @@ abstract class AbstractService
*/
public function getLdap()
{
if (empty($this->ldap)){
$this->ldap = $this->getServiceLocator()->get('ldap');
}
return $this->ldap;
}
......
......@@ -2,27 +2,48 @@
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)
{
return $this->__invoke($serviceLocator, '?');
}
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return Generic
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return object|Generic
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$service = new Generic();
/**
* @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->setServiceLocator($serviceLocator);
$service = new Generic();
$service->setLdap($ldap);
$service->setLdapPeopleService($ldapPeopleService);
$service->setLdapStructureService($ldapStructureService);
$service->setLdapGroupService($ldapGroupService);
$service->setLdapSystemService($ldapSystemService);
return $service;
}
......
......@@ -2,27 +2,48 @@
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)
{
return $this->__invoke($serviceLocator, '?');
}
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return Group
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return object|Group
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$service = new Group();
/**
* @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->setServiceLocator($serviceLocator);
$service = new Group();
$service->setLdap($ldap);
$service->setLdapPeopleService($ldapPeopleService);
$service->setLdapStructureService($ldapStructureService);
$service->setLdapSystemService($ldapSystemService);
$service->setLdapGenericService($ldapGenericService);
return $service;
}
......
<?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();
}
<?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
<?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();
}
<?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
......@@ -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();
}
......@@ -18,4 +18,12 @@ trait LdapPeopleServiceAwareTrait
{
$this->ldapPeopleService = $ldapPeopleService;
}
/**
* @return LdapPeopleService
*/
public function getLdapPeopleService()
{
return $this->ldapPeopleService;
}
}
\ No newline at end of file
<?php
namespace UnicaenLdap\Service;
use UnicaenLdap\Service\Structure as LdapStructureService;
interface LdapStructureServiceAwareInterface