Loading src/UnicaenLdap/Entity/Base/People.php +5 −44 Changes for src/UnicaenLdap/Entity/Base/People.php: 5 added lines, 44 removed lines. Original line number Diff line number Diff line Loading @@ -33,11 +33,13 @@ class People extends Entity 'person', 'eduPerson', 'supannPerson', 'schacPersonalCharacteristics', 'schacEntryMetadata', 'ucbnEmp', 'ucbnEtu', 'posixAccount', 'sambaAccount', 'sambaSamAcount', "schacPersonalCharacteristics", "schacEntryMetadata" 'sambaSamAccount', ]; /** Loading Loading @@ -228,56 +230,15 @@ class People extends Entity 'TITULAIRE', ]; /** * Liste des patterns génériques utilisés pour différents attributs */ static protected $attribute_with_label_pattern = '/^\{(?<etiquette>[\w-:]+)\}(?<identifiant>.+)$/'; /** * Liste des patterns spécifiques utilisés pour différents attributs */ static protected $structure_pattern = '/^(?<code>[\w-]+);(?<libelle>.+)$/'; static protected $secteur_disciplinaire_pattern = '/^(?<code>[\d]+);(?<libelle>.+)$/'; static protected $postal_address_pattern = '/^(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)$/'; static protected $role_pattern = '/^\[role=(?<role>[\w-]+)\]\[type=(?<type>[\w-]+)\]\[code=(?<code>[\w-]+)\]\[libelle=(?<libelle>.+)\]$/'; static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)$/'; /** * Ajoute ou affecte une valeur à un attribut Ldap * * @param string $attrName * @param mixed $value * @param bool $append * @throws Exception * @throws LdapException */ protected function appendOrNot($attrName, $value, $append) { (!$append) ? $this->set($attrName, $value) : $this->add($attrName, $value); } /** * Vérifie une valeur et supprime les valeurs nulles * * @param mixed $value * @return array */ protected function preFormat($value) { if (is_scalar($value) || is_null($value) || is_a($value, 'DateTime')) { $value = [$value]; } $value = array_filter($value); return $value; } /** * Attribut Ldap "sn" * Loading src/UnicaenLdap/Entity/Base/Structure.php +191 −0 Changes for src/UnicaenLdap/Entity/Base/Structure.php: 191 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,9 @@ namespace UnicaenLdap\Entity\Base; use UnicaenLdap\Entity\Entity; use UnicaenLdap\Entity\Structure as StructureEntity; use UnicaenLdap\Exception; use Zend\Ldap\Exception\LdapException; /** * Classe mère des entités de la branche "structures" de l'annuaire LDAP. Loading @@ -25,6 +28,25 @@ class Structure extends Entity 'ucbnEntite', ]; /** * Liste des attributs autorisés pour une entité "People" * * @var array */ protected $authorizedAttributes = [ // Attributes classes 'objectClass', // Attributes 'description', 'facsimileTelephoneNumber', 'ou', 'postalAddress', 'supannCodeEntiteParent', 'supannRefId', 'supannTypeEntite', 'telephoneNumber', ]; /** * Liste des attributs contenant des dates * Loading @@ -38,4 +60,173 @@ class Structure extends Entity * @var array */ protected $monoValuedAttributes = []; /** * Attribut Ldap "description" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setDescription($value = null, $append = false) { $value = $this->preFormat($value); $this->appendOrNot('description', $value, $append); return $this; } /** * Attribut Ldap "ou" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setOu($value = null, $append = false) { $value = $this->preFormat($value); $this->appendOrNot('ou', $value, $append); return $this; } /** * Attribut Ldap "supannCodeEntiteParent" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannCodeEntiteParent($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map(function ($val) { if (is_string($val)) { if (0 !== strpos($val, $this->getService()->getCodeStructurePrefixe())) { $val = $this->getService()->getCodeStructurePrefixe() . $val; } return $val; } elseif ($val instanceof StructureEntity) { return $val->get('supannCodeEntite'); } else { return null; } }, $value); $this->appendOrNot('supannCodeEntiteParent', array_filter($value), $append); return $this; } /** * Attribut Ldap "supannTypeEntite" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannTypeEntiteAffectation($value = null, $append = false) { $value = $this->preFormat($value); $supannLabel = $this->getLabel('SUPANN'); $value = array_map(function ($val) use ($supannLabel) { if (is_string($val)) { return preg_match("/^$supannLabel.+$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val); } else { return null; } }, $value); $this->appendOrNot('supannTypeEntite', array_filter($value), $append); return $this; } /** * Attribut Ldap "telephoneNumber" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setTelephoneNumber($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map([$this, 'formatTel'], $value); $this->appendOrNot('telephoneNumber', $value, $append); return $this; } /** * Attribut Ldap "facsimileTelephoneNumber" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setFacsimileTelephoneNumber($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map([$this, 'formatTel'], $value); $this->appendOrNot('facsimileTelephoneNumber', $value, $append); return $this; } /** * Attribut Ldap "postalAddress" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setPostalAddress($value = null, $append = false) { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match(self::$postal_address_pattern, $v); }); $this->appendOrNot('postalAddress', $value, $append); return $this; } /** * Attribut Ldap "supannRefId" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannRefId($value = null, $append = false) { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match(self::$attribute_with_label_pattern, $v); }); $this->appendOrNot('supannRefId', $value, $append); return $this; } } No newline at end of file src/UnicaenLdap/Entity/Entity.php +45 −0 Changes for src/UnicaenLdap/Entity/Entity.php: 45 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -65,6 +65,16 @@ abstract class Entity */ protected $monoValuedAttributes = []; /** * Liste des patterns génériques utilisés pour différents attributs */ static protected $attribute_with_label_pattern = '/^\{(?<etiquette>[\w-:]+)\}(?<identifiant>.+)$/'; /** * Liste des patterns spécifiques utilisés pour différents attributs */ static protected $postal_address_pattern = '/^(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)$/'; /** * @param string $type type d'entité Loading Loading @@ -345,6 +355,22 @@ abstract class Entity return $this; } /** * Ajoute ou affecte une valeur à un attribut Ldap * * @param string $attrName * @param mixed $value * @param bool $append * @throws Exception * @throws LdapException */ protected function appendOrNot($attrName, $value, $append) { (!$append) ? $this->set($attrName, $value) : $this->add($attrName, $value); } /** * Méthode magique... * Loading Loading @@ -495,4 +521,23 @@ abstract class Entity return null; } } /** * Vérifie une valeur et supprime les valeurs nulles * * @param mixed $value * @return array */ protected function preFormat($value) { if (is_scalar($value) || is_null($value) || is_a($value, 'DateTime')) { $value = [$value]; } $value = array_filter($value); return $value; } } No newline at end of file Loading
src/UnicaenLdap/Entity/Base/People.php +5 −44 Changes for src/UnicaenLdap/Entity/Base/People.php: 5 added lines, 44 removed lines. Original line number Diff line number Diff line Loading @@ -33,11 +33,13 @@ class People extends Entity 'person', 'eduPerson', 'supannPerson', 'schacPersonalCharacteristics', 'schacEntryMetadata', 'ucbnEmp', 'ucbnEtu', 'posixAccount', 'sambaAccount', 'sambaSamAcount', "schacPersonalCharacteristics", "schacEntryMetadata" 'sambaSamAccount', ]; /** Loading Loading @@ -228,56 +230,15 @@ class People extends Entity 'TITULAIRE', ]; /** * Liste des patterns génériques utilisés pour différents attributs */ static protected $attribute_with_label_pattern = '/^\{(?<etiquette>[\w-:]+)\}(?<identifiant>.+)$/'; /** * Liste des patterns spécifiques utilisés pour différents attributs */ static protected $structure_pattern = '/^(?<code>[\w-]+);(?<libelle>.+)$/'; static protected $secteur_disciplinaire_pattern = '/^(?<code>[\d]+);(?<libelle>.+)$/'; static protected $postal_address_pattern = '/^(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)$/'; static protected $role_pattern = '/^\[role=(?<role>[\w-]+)\]\[type=(?<type>[\w-]+)\]\[code=(?<code>[\w-]+)\]\[libelle=(?<libelle>.+)\]$/'; static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)$/'; /** * Ajoute ou affecte une valeur à un attribut Ldap * * @param string $attrName * @param mixed $value * @param bool $append * @throws Exception * @throws LdapException */ protected function appendOrNot($attrName, $value, $append) { (!$append) ? $this->set($attrName, $value) : $this->add($attrName, $value); } /** * Vérifie une valeur et supprime les valeurs nulles * * @param mixed $value * @return array */ protected function preFormat($value) { if (is_scalar($value) || is_null($value) || is_a($value, 'DateTime')) { $value = [$value]; } $value = array_filter($value); return $value; } /** * Attribut Ldap "sn" * Loading
src/UnicaenLdap/Entity/Base/Structure.php +191 −0 Changes for src/UnicaenLdap/Entity/Base/Structure.php: 191 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,9 @@ namespace UnicaenLdap\Entity\Base; use UnicaenLdap\Entity\Entity; use UnicaenLdap\Entity\Structure as StructureEntity; use UnicaenLdap\Exception; use Zend\Ldap\Exception\LdapException; /** * Classe mère des entités de la branche "structures" de l'annuaire LDAP. Loading @@ -25,6 +28,25 @@ class Structure extends Entity 'ucbnEntite', ]; /** * Liste des attributs autorisés pour une entité "People" * * @var array */ protected $authorizedAttributes = [ // Attributes classes 'objectClass', // Attributes 'description', 'facsimileTelephoneNumber', 'ou', 'postalAddress', 'supannCodeEntiteParent', 'supannRefId', 'supannTypeEntite', 'telephoneNumber', ]; /** * Liste des attributs contenant des dates * Loading @@ -38,4 +60,173 @@ class Structure extends Entity * @var array */ protected $monoValuedAttributes = []; /** * Attribut Ldap "description" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setDescription($value = null, $append = false) { $value = $this->preFormat($value); $this->appendOrNot('description', $value, $append); return $this; } /** * Attribut Ldap "ou" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setOu($value = null, $append = false) { $value = $this->preFormat($value); $this->appendOrNot('ou', $value, $append); return $this; } /** * Attribut Ldap "supannCodeEntiteParent" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannCodeEntiteParent($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map(function ($val) { if (is_string($val)) { if (0 !== strpos($val, $this->getService()->getCodeStructurePrefixe())) { $val = $this->getService()->getCodeStructurePrefixe() . $val; } return $val; } elseif ($val instanceof StructureEntity) { return $val->get('supannCodeEntite'); } else { return null; } }, $value); $this->appendOrNot('supannCodeEntiteParent', array_filter($value), $append); return $this; } /** * Attribut Ldap "supannTypeEntite" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannTypeEntiteAffectation($value = null, $append = false) { $value = $this->preFormat($value); $supannLabel = $this->getLabel('SUPANN'); $value = array_map(function ($val) use ($supannLabel) { if (is_string($val)) { return preg_match("/^$supannLabel.+$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val); } else { return null; } }, $value); $this->appendOrNot('supannTypeEntite', array_filter($value), $append); return $this; } /** * Attribut Ldap "telephoneNumber" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setTelephoneNumber($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map([$this, 'formatTel'], $value); $this->appendOrNot('telephoneNumber', $value, $append); return $this; } /** * Attribut Ldap "facsimileTelephoneNumber" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setFacsimileTelephoneNumber($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map([$this, 'formatTel'], $value); $this->appendOrNot('facsimileTelephoneNumber', $value, $append); return $this; } /** * Attribut Ldap "postalAddress" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setPostalAddress($value = null, $append = false) { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match(self::$postal_address_pattern, $v); }); $this->appendOrNot('postalAddress', $value, $append); return $this; } /** * Attribut Ldap "supannRefId" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannRefId($value = null, $append = false) { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match(self::$attribute_with_label_pattern, $v); }); $this->appendOrNot('supannRefId', $value, $append); return $this; } } No newline at end of file
src/UnicaenLdap/Entity/Entity.php +45 −0 Changes for src/UnicaenLdap/Entity/Entity.php: 45 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -65,6 +65,16 @@ abstract class Entity */ protected $monoValuedAttributes = []; /** * Liste des patterns génériques utilisés pour différents attributs */ static protected $attribute_with_label_pattern = '/^\{(?<etiquette>[\w-:]+)\}(?<identifiant>.+)$/'; /** * Liste des patterns spécifiques utilisés pour différents attributs */ static protected $postal_address_pattern = '/^(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)$/'; /** * @param string $type type d'entité Loading Loading @@ -345,6 +355,22 @@ abstract class Entity return $this; } /** * Ajoute ou affecte une valeur à un attribut Ldap * * @param string $attrName * @param mixed $value * @param bool $append * @throws Exception * @throws LdapException */ protected function appendOrNot($attrName, $value, $append) { (!$append) ? $this->set($attrName, $value) : $this->add($attrName, $value); } /** * Méthode magique... * Loading Loading @@ -495,4 +521,23 @@ abstract class Entity return null; } } /** * Vérifie une valeur et supprime les valeurs nulles * * @param mixed $value * @return array */ protected function preFormat($value) { if (is_scalar($value) || is_null($value) || is_a($value, 'DateTime')) { $value = [$value]; } $value = array_filter($value); return $value; } } No newline at end of file