Skip to content
Snippets Groups Projects
Commit 4cf665d0 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Dépôt initial

parents
No related branches found
No related tags found
No related merge requests found
<?php
namespace UnicaenUtilisateurLdapAdapter;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\Glob;
use Zend\Config\Factory as ConfigFactory;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
/* Active un layout spécial si la requête est de type AJAX. Valable pour TOUS les modules de l'application. */
$eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch',
function (MvcEvent $e) {
$request = $e->getRequest();
if ($request instanceof HttpRequest && $request->isXmlHttpRequest()) {
$e->getTarget()->layout('layout/ajax.phtml');
}
}
);
}
public function getConfig()
{
$configInit = [
__DIR__ . '/config/module.config.php'
];
$configFiles = ArrayUtils::merge(
$configInit,
Glob::glob(__DIR__ . '/config/merged/{,*.}{config}.php', Glob::GLOB_BRACE)
);
return ConfigFactory::fromFiles($configFiles);
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
{
"name": "unicaen/utilisateur-ldap-adapter",
"description": "Module fournissant le service pour l'adpatation de unicaen/ldap sur unicaen/utilisateur",
"repositories": [
{
"type": "composer",
"url": "https://gest.unicaen.fr/packagist"
}
],
"require": {
"unicaen/utilisateur": "dev-zf-3.x",
"unicaen/ldap": "dev-zf-3.x"
},
"autoload": {
"psr-0": {
"UnicaenUtilisateurLdapAdapter": "src/"
},
"classmap": [
"./Module.php"
]
}
}
<?php
use UnicaenUtilisateurLdapAdapter\Service\LdapService;
use UnicaenUtilisateurLdapAdapter\Service\LdapServiceFactory;
return [
'service_manager' => [
'factories' => [
LdapService::class => LdapServiceFactory::class,
],
],
];
\ No newline at end of file
#Unicaen Utilisateur LDAP Adpater
## But du module
Le but de cet adaptateur est de fournir une service effectuant une recherche dans le LDAP en garantissant le contract des
interface de `Unicaen/Utilisateur` : `RechercheIndividuServiceInterface` et `RechercheIndividuResultatInterface`.
Cela sans modification de `Unicaen/Ldap`.
## Historique des versions
**version 0.1.1** 16/10/2019
- version initial fournissant le service de recherche
## Amélioration et/ou changement à venir
Aucun
\ No newline at end of file
<?php
namespace UnicaenUtilisateurLdapAdapter\Entity;
use UnicaenLdap\Entity\People;
use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuResultatInterface;
class LdapIndividu implements RechercheIndividuResultatInterface {
/** @var \UnicaenLdap\Entity\People */
private $people;
/**
* @return \UnicaenLdap\Entity\People
*/
public function getPeople()
{
return $this->people;
}
/**
* @param \UnicaenLdap\Entity\People $people
* @return People
*/
public function setPeople($people)
{
$this->people = $people;
return $this;
}
public function getId()
{
return $this->people->getId();
}
public function getUsername()
{
return $this->people->get('supannAliasLogin');
}
public function getDisplayname()
{
$tmp_name = $this->people->get('sn');
if (!is_string($tmp_name)) $tmp_name = implode("-",$this->people->get('sn'));
return $tmp_name . " ". $this->people->get('givenName');
}
public function getEmail()
{
return $this->people->get('mail');
}
}
\ No newline at end of file
<?php
namespace UnicaenUtilisateurLdapAdapter\Service;
use UnicaenLdap\Exception;
use UnicaenLdap\Filter\People as PeopleFilter;
use UnicaenLdap\Service\People as PeopleService;
use UnicaenLdap\Entity\People as PeopleEntity;
use UnicaenLdap\Service\LdapPeopleServiceAwareTrait;
use UnicaenUtilisateurLdapAdapter\Entity\LdapIndividu;
use UnicaenUtilisateur\Exception\RuntimeException;
use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuResultatInterface;
use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuServiceInterface;
class LdapService implements RechercheIndividuServiceInterface {
use LdapPeopleServiceAwareTrait;
/**
* @param $id
* @return RechercheIndividuResultatInterface
*/
public function findById($id)
{
/**
* @var PeopleEntity $people
*/
$people = $this->ldapPeopleService->get($id);
$p = new LdapIndividu();
$p->setPeople($people);
return $p;
}
/**
* @param string $term
* @return RechercheIndividuResultatInterface[]
*/
public function findByTerm(string $term)
{
$people = null;
$filter = PeopleFilter::orFilter(
PeopleFilter::username($term),
PeopleFilter::nameContains($term)
);
/** @var PeopleService $ldapService */
try {
$people = $this->ldapPeopleService->search($filter);
} catch (Exception $e) {
throw new RuntimeException("Un exception ldap est survenue :", $e);
}
$res = [];
/** @var PeopleEntity $peep */
foreach ($people as $peep) {
$p = new LdapIndividu();
$p->setPeople($peep);
$res[] = $p;
}
return $res;
}
}
\ No newline at end of file
<?php
namespace UnicaenUtilisateurLdapAdapter\Service;
use Interop\Container\ContainerInterface;
use UnicaenLdap\Service\People;
class LdapServiceFactory {
/**
* @param ContainerInterface $container
* @return LdapService
*/
public function __invoke(ContainerInterface $container) {
/**
* @var People $ldapService
*/
$ldapService = $container->get(People::class);
/** @var LdapService $service */
$service = new LdapService();
$service->setLdapPeopleService($ldapService);
return $service;
}
}
\ 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