Loading config/unicaen-ldap.local.php.dist +5 −5 Changes for config/unicaen-ldap.local.php.dist: 5 added lines, 5 removed lines. Original line number Diff line number Diff line <?php return array( 'unicaen-ldap' => array( return [ 'unicaen-ldap' => [ 'host' => 'host.domain.fr', 'port' => 389, 'version' => 3, 'baseDn' => "ou=xxxxxxxxxxx,dc=domain,dc=fr", 'baseDn' => "dc=domain,dc=fr", // racine de l'annuaire 'bindRequiresDn' => true, 'username' => "uid=xxxxxxxxx,ou=xxxxxxxxxx,dc=domain,dc=fr", 'password' => "xxxxxxxxxxxx", 'accountFilterFormat' => "(&(objectClass=posixAccount)(supannAliasLogin=%s))", ) ); ] ]; src/UnicaenLdap/Entity/Base/People.php +414 −181 File changed.Preview size limit exceeded, changes collapsed. Show changes src/UnicaenLdap/Entity/Base/Structure.php 0 → 100644 +41 −0 Changes for src/UnicaenLdap/Entity/Base/Structure.php: 41 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity\Base; use UnicaenLdap\Entity\Entity; /** * Classe mère des entités de la branche "structures" de l'annuaire LDAP. * * @author David Surville <david.surville@unicaen.fr> */ class Structure extends Entity { protected $type = 'Structure'; /** * Liste des classes d'objet nécessaires à la création d'une structure * * @var string[] */ protected $objectClass = [ 'top', 'organizationalUnit', 'supannEntite', 'ucbnEntite', ]; /** * Liste des attributs contenant des dates * * @var array */ protected $dateTimeAttributes = []; /** * Liste des attributs monovalués * * @var array */ protected $monoValuedAttributes = []; } No newline at end of file src/UnicaenLdap/Entity/Entity.php +117 −41 Changes for src/UnicaenLdap/Entity/Entity.php: 117 added lines, 41 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace UnicaenLdap\Entity; use UnicaenLdap\Node; use UnicaenLdap\Exception; use UnicaenLdap\Service\AbstractService; use UnicaenLdap\Util; use Zend\Ldap\Dn; use Zend\Ldap\Exception\LdapException; Loading @@ -15,6 +16,8 @@ use Zend\Ldap\Exception\LdapException; */ abstract class Entity { static protected $etablissement_domaine = 'unicaen.fr'; /** * Type d'entité * Loading Loading @@ -42,37 +45,18 @@ abstract class Entity protected $objectClass = []; /** * Liste des labels utilisés dans les différents attributs * Liste des attributs contenant des dates * * @var array */ // protected $labels = [ // 'AUTRE' => 'AUTRE', // Texte libre // 'BAP' => 'BAP', // Branche d'Activité Professionnelle REFERENS // 'CNRS' => 'CNRS', // LABINTEL (CNRS) // 'CNU' => 'CNU', // Section CNU // 'INRA' => 'INRA', // INRA // 'INRIA' => 'INRIA', // INRIA // 'INSERM' => 'INSERM', // INSERM // 'NCORPS' => 'NCORPS', // BCN: code issu de la colonne “CORPS” de la table “N_CORPS” du domaine “Gestion du personnel” // 'REFERENS' => 'REFERENS', // Emploi-type REFERENS // 'SAML' => 'SAML', // Fédération d'identités // 'SILLAND' => 'SILLAND', // Fonction SILLAND // 'SIRET' => 'SIRET', // SIRET (INSEE) // 'SISE' => 'SISE', // BCN: valeur “DIPLOME SISE” de la table N_DIPLOME_SISE // 'SUPANN' => 'SUPANN', // Label nomenclatures SupAnn // 'TVA' => 'TVA', // Union Européenne // 'UAI' => 'UAI', // Unité Administrative Immatriculée (UAI) // 'UAI_ETABLISSEMENT' => 'UAI:%s', // // ]; protected $dateTimeAttributes = []; /** * Liste des attributs contenant des dates * Liste des attributs monovalués * * @var array */ protected $dateTimeAttributes = []; protected $monoValuedAttributes = []; /** Loading Loading @@ -113,7 +97,7 @@ abstract class Entity } /** * Retourne le type du service * Retourne le type de l'entité * * @return string */ Loading Loading @@ -152,17 +136,6 @@ abstract class Entity $this->node = $node; } /** * Retourne un label en fonction d'une clé * * @param $key * @return null|string */ // public function getLabel($key) // { // return $this->labels[$key]; // } /** * Retourne le Dn de l'entité sous forme de chaîne de caractères * Loading @@ -174,7 +147,7 @@ abstract class Entity } /** * Retourne la clé primaire correspondant à l'entité * Retourne le nom de la clé primaire correspondant à l'entité * * @return mixed * @throws Exception Loading @@ -196,6 +169,17 @@ abstract class Entity return $this->get($this->getKey()); } /** * Retourne l'attribut "objectClass" * * @return array|int|mixed|null * @throws LdapException */ public function getObjectClass() { return $this->get('objectClass'); } /** * Retourne la liste des attributs de l'entité * Loading @@ -206,6 +190,27 @@ abstract class Entity return array_keys($this->getNode()->getAttributes()); } /** * Retourne un label constitué des différentes clés passées en paramètre * Format : {$key1:$key2:$key3:...} * * @param string ...$key * @return string */ public function getLabel(...$key) { $label = ''; $c = 0; foreach($key as $k) { if(is_string($k)) { $label .= ($c == 0) ? $k : ":$k"; } $c++; } return sprintf('{%s}', $label); } /** * Exporte sous forme de tableau le contenu de l'entité * Loading Loading @@ -252,10 +257,17 @@ abstract class Entity * @param string $attrName * @param mixed $value * @return self * @throws Exception * @throws LdapException */ public function set($attrName, $value) { if(is_array($value) && count($value) > 1 && in_array($attrName, $this->monoValuedAttributes)) { throw new Exception(sprintf("L'attribut Ldap '%s' est monovalué et ne doit contenir qu'une seule valeur.", $attrName)); } if (in_array($attrName, $this->dateTimeAttributes)) { $this->getNode()->setDateTimeAttribute($attrName, $value, true); } else { Loading @@ -279,14 +291,20 @@ abstract class Entity /** * Ajoute une valeur à un attribut * Si l'attribut est monovalué, la valeur actuelle est remplacée par la nouvelle valeur * * @param string $attrName * @param mixed $value * @return self * @throws Exception * @throws LdapException */ public function add($attrName, $value) { if(in_array($attrName, $this->monoValuedAttributes)) { $this->set($attrName, $value); } else { if (in_array($attrName, $this->dateTimeAttributes)) { $this->getNode()->appendToDateTimeAttribute($attrName, $value); } else { Loading @@ -295,6 +313,7 @@ abstract class Entity return $this; } } /** * Retire une valeur à un attribut Loading Loading @@ -394,13 +413,70 @@ abstract class Entity } /** * Retourne l'attribut "objectClass" * Formate un nom ou un prénom * * @return array|int|mixed|null * @throws LdapException * @param string $name * @param bool $removeAccents remplace les caractères avec un signe diacritique * @return mixed|null|string|string[] */ public function getObjectClass() protected function formatName($name, $removeAccents = false) { return $this->get('objectClass'); $name = preg_replace('/[[:blank:]]+/', ' ', trim($name)); if ($removeAccents) { $name = Util::removeAccents($name); } return mb_convert_case($name, MB_CASE_TITLE, "UTF-8"); } /** * Formate un numéro de téléphone (0XXXXXXXXX) au format international (+33 X XX XX XX XX) * * @param string $num * @return string */ protected function formatTel($num) { if (is_null($num)) { return null; } $num = preg_replace('/\s+/', '', $num); return preg_match("/0\d{9}/", $num) ? preg_replace("/0(\d{1})(\d{2})(\d{2})(\d{2})(\d{2})/", "+33 $1 $2 $3 $4 $5", $num) : $num; } /** * Formate les données sources correspondant à un booléen * * @param mixed $value * @return string */ protected function formatBoolean($value) { if (!is_bool($value) && $value === null) { return null; } if (is_string($value)) { $value = strtolower($value); } switch (true) { case $value === false; case $value === 0: case $value === 'n': return 'FALSE'; case $value === true: case $value === 1: case $value === 'o': case $value === 'y': return 'TRUE'; default: return null; } } } No newline at end of file src/UnicaenLdap/Entity/People.php +3 −4 Changes for src/UnicaenLdap/Entity/People.php: 3 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -6,15 +6,14 @@ use UnicaenLdap\Entity\Base\People as BasePeople; use DateTime; /** * Classe mère des people de l'annuaire LDAP. * Classe de gestion des entités de la branche "people" de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> * @author David SURVILLE <david.surville@unicaen.fr> */ class People extends BasePeople { static protected $role_pattern = '/^\[role={SUPANN}(.*)\]\[type={SUPANN}(.*)\]\[code=(.*)\]\[libelle=(.*)\]$/'; /** * Liste des rôles existants * Loading Loading @@ -87,7 +86,7 @@ class People extends BasePeople */ public function getOu() { if ($result = $this->getNode()->getDn()->get(1)) { if ($result = $this->getDn()->get(1)) { return $result['ou']; } Loading Loading
config/unicaen-ldap.local.php.dist +5 −5 Changes for config/unicaen-ldap.local.php.dist: 5 added lines, 5 removed lines. Original line number Diff line number Diff line <?php return array( 'unicaen-ldap' => array( return [ 'unicaen-ldap' => [ 'host' => 'host.domain.fr', 'port' => 389, 'version' => 3, 'baseDn' => "ou=xxxxxxxxxxx,dc=domain,dc=fr", 'baseDn' => "dc=domain,dc=fr", // racine de l'annuaire 'bindRequiresDn' => true, 'username' => "uid=xxxxxxxxx,ou=xxxxxxxxxx,dc=domain,dc=fr", 'password' => "xxxxxxxxxxxx", 'accountFilterFormat' => "(&(objectClass=posixAccount)(supannAliasLogin=%s))", ) ); ] ];
src/UnicaenLdap/Entity/Base/People.php +414 −181 File changed.Preview size limit exceeded, changes collapsed. Show changes
src/UnicaenLdap/Entity/Base/Structure.php 0 → 100644 +41 −0 Changes for src/UnicaenLdap/Entity/Base/Structure.php: 41 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity\Base; use UnicaenLdap\Entity\Entity; /** * Classe mère des entités de la branche "structures" de l'annuaire LDAP. * * @author David Surville <david.surville@unicaen.fr> */ class Structure extends Entity { protected $type = 'Structure'; /** * Liste des classes d'objet nécessaires à la création d'une structure * * @var string[] */ protected $objectClass = [ 'top', 'organizationalUnit', 'supannEntite', 'ucbnEntite', ]; /** * Liste des attributs contenant des dates * * @var array */ protected $dateTimeAttributes = []; /** * Liste des attributs monovalués * * @var array */ protected $monoValuedAttributes = []; } No newline at end of file
src/UnicaenLdap/Entity/Entity.php +117 −41 Changes for src/UnicaenLdap/Entity/Entity.php: 117 added lines, 41 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace UnicaenLdap\Entity; use UnicaenLdap\Node; use UnicaenLdap\Exception; use UnicaenLdap\Service\AbstractService; use UnicaenLdap\Util; use Zend\Ldap\Dn; use Zend\Ldap\Exception\LdapException; Loading @@ -15,6 +16,8 @@ use Zend\Ldap\Exception\LdapException; */ abstract class Entity { static protected $etablissement_domaine = 'unicaen.fr'; /** * Type d'entité * Loading Loading @@ -42,37 +45,18 @@ abstract class Entity protected $objectClass = []; /** * Liste des labels utilisés dans les différents attributs * Liste des attributs contenant des dates * * @var array */ // protected $labels = [ // 'AUTRE' => 'AUTRE', // Texte libre // 'BAP' => 'BAP', // Branche d'Activité Professionnelle REFERENS // 'CNRS' => 'CNRS', // LABINTEL (CNRS) // 'CNU' => 'CNU', // Section CNU // 'INRA' => 'INRA', // INRA // 'INRIA' => 'INRIA', // INRIA // 'INSERM' => 'INSERM', // INSERM // 'NCORPS' => 'NCORPS', // BCN: code issu de la colonne “CORPS” de la table “N_CORPS” du domaine “Gestion du personnel” // 'REFERENS' => 'REFERENS', // Emploi-type REFERENS // 'SAML' => 'SAML', // Fédération d'identités // 'SILLAND' => 'SILLAND', // Fonction SILLAND // 'SIRET' => 'SIRET', // SIRET (INSEE) // 'SISE' => 'SISE', // BCN: valeur “DIPLOME SISE” de la table N_DIPLOME_SISE // 'SUPANN' => 'SUPANN', // Label nomenclatures SupAnn // 'TVA' => 'TVA', // Union Européenne // 'UAI' => 'UAI', // Unité Administrative Immatriculée (UAI) // 'UAI_ETABLISSEMENT' => 'UAI:%s', // // ]; protected $dateTimeAttributes = []; /** * Liste des attributs contenant des dates * Liste des attributs monovalués * * @var array */ protected $dateTimeAttributes = []; protected $monoValuedAttributes = []; /** Loading Loading @@ -113,7 +97,7 @@ abstract class Entity } /** * Retourne le type du service * Retourne le type de l'entité * * @return string */ Loading Loading @@ -152,17 +136,6 @@ abstract class Entity $this->node = $node; } /** * Retourne un label en fonction d'une clé * * @param $key * @return null|string */ // public function getLabel($key) // { // return $this->labels[$key]; // } /** * Retourne le Dn de l'entité sous forme de chaîne de caractères * Loading @@ -174,7 +147,7 @@ abstract class Entity } /** * Retourne la clé primaire correspondant à l'entité * Retourne le nom de la clé primaire correspondant à l'entité * * @return mixed * @throws Exception Loading @@ -196,6 +169,17 @@ abstract class Entity return $this->get($this->getKey()); } /** * Retourne l'attribut "objectClass" * * @return array|int|mixed|null * @throws LdapException */ public function getObjectClass() { return $this->get('objectClass'); } /** * Retourne la liste des attributs de l'entité * Loading @@ -206,6 +190,27 @@ abstract class Entity return array_keys($this->getNode()->getAttributes()); } /** * Retourne un label constitué des différentes clés passées en paramètre * Format : {$key1:$key2:$key3:...} * * @param string ...$key * @return string */ public function getLabel(...$key) { $label = ''; $c = 0; foreach($key as $k) { if(is_string($k)) { $label .= ($c == 0) ? $k : ":$k"; } $c++; } return sprintf('{%s}', $label); } /** * Exporte sous forme de tableau le contenu de l'entité * Loading Loading @@ -252,10 +257,17 @@ abstract class Entity * @param string $attrName * @param mixed $value * @return self * @throws Exception * @throws LdapException */ public function set($attrName, $value) { if(is_array($value) && count($value) > 1 && in_array($attrName, $this->monoValuedAttributes)) { throw new Exception(sprintf("L'attribut Ldap '%s' est monovalué et ne doit contenir qu'une seule valeur.", $attrName)); } if (in_array($attrName, $this->dateTimeAttributes)) { $this->getNode()->setDateTimeAttribute($attrName, $value, true); } else { Loading @@ -279,14 +291,20 @@ abstract class Entity /** * Ajoute une valeur à un attribut * Si l'attribut est monovalué, la valeur actuelle est remplacée par la nouvelle valeur * * @param string $attrName * @param mixed $value * @return self * @throws Exception * @throws LdapException */ public function add($attrName, $value) { if(in_array($attrName, $this->monoValuedAttributes)) { $this->set($attrName, $value); } else { if (in_array($attrName, $this->dateTimeAttributes)) { $this->getNode()->appendToDateTimeAttribute($attrName, $value); } else { Loading @@ -295,6 +313,7 @@ abstract class Entity return $this; } } /** * Retire une valeur à un attribut Loading Loading @@ -394,13 +413,70 @@ abstract class Entity } /** * Retourne l'attribut "objectClass" * Formate un nom ou un prénom * * @return array|int|mixed|null * @throws LdapException * @param string $name * @param bool $removeAccents remplace les caractères avec un signe diacritique * @return mixed|null|string|string[] */ public function getObjectClass() protected function formatName($name, $removeAccents = false) { return $this->get('objectClass'); $name = preg_replace('/[[:blank:]]+/', ' ', trim($name)); if ($removeAccents) { $name = Util::removeAccents($name); } return mb_convert_case($name, MB_CASE_TITLE, "UTF-8"); } /** * Formate un numéro de téléphone (0XXXXXXXXX) au format international (+33 X XX XX XX XX) * * @param string $num * @return string */ protected function formatTel($num) { if (is_null($num)) { return null; } $num = preg_replace('/\s+/', '', $num); return preg_match("/0\d{9}/", $num) ? preg_replace("/0(\d{1})(\d{2})(\d{2})(\d{2})(\d{2})/", "+33 $1 $2 $3 $4 $5", $num) : $num; } /** * Formate les données sources correspondant à un booléen * * @param mixed $value * @return string */ protected function formatBoolean($value) { if (!is_bool($value) && $value === null) { return null; } if (is_string($value)) { $value = strtolower($value); } switch (true) { case $value === false; case $value === 0: case $value === 'n': return 'FALSE'; case $value === true: case $value === 1: case $value === 'o': case $value === 'y': return 'TRUE'; default: return null; } } } No newline at end of file
src/UnicaenLdap/Entity/People.php +3 −4 Changes for src/UnicaenLdap/Entity/People.php: 3 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -6,15 +6,14 @@ use UnicaenLdap\Entity\Base\People as BasePeople; use DateTime; /** * Classe mère des people de l'annuaire LDAP. * Classe de gestion des entités de la branche "people" de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> * @author David SURVILLE <david.surville@unicaen.fr> */ class People extends BasePeople { static protected $role_pattern = '/^\[role={SUPANN}(.*)\]\[type={SUPANN}(.*)\]\[code=(.*)\]\[libelle=(.*)\]$/'; /** * Liste des rôles existants * Loading Loading @@ -87,7 +86,7 @@ class People extends BasePeople */ public function getOu() { if ($result = $this->getNode()->getDn()->get(1)) { if ($result = $this->getDn()->get(1)) { return $result['ou']; } Loading