Loading Module.php +24 −3 Changes for Module.php: 24 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -50,10 +50,31 @@ class Module implements ConfigProviderInterface, ServiceProviderInterface */ public function getServiceConfig() { return array( 'factories' => array( $services = array( 'Generic', 'Group', 'People', 'Structure', 'System' ); $processus = array( ); $factories = array( 'ldap' => 'UnicaenLdap\LdapFactory', 'ldapOptions' => 'UnicaenLdap\Options\ModuleOptionsFactory', ), ); foreach( $services as $service ){ $factories['ldapService'.$service] = function($sm) use ($service){ $className = 'UnicaenLdap\\Service\\'.$service; return new $className; }; } foreach( $processus as $proc ){ $factories['ldapProcessus'.$proc] = function($sm) use ($proc){ $className = 'UnicaenLdap\\Processus\\'.$proc; return new $className; }; } return array( 'factories' => $factories, ); } } src/UnicaenLdap/Collection.php +120 Changes for src/UnicaenLdap/Collection.php: 120 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap; use Countable; use Iterator; use UnicaenLdap\Service\Service; use UnicaenLdap\Entity\Entity; /** * Liste d'entités */ class Collection implements Iterator, Countable { /** * * * @var Service */ private $service; /** * Liste des identifiants à parcourir * * @var string[] */ private $data; /** * * @var integer */ private $index = 0; /** * Constructor. * * @param Service $service * @param string[] $data */ public function __construct( Service $service, array $data ) { $this->service = $service; $this->data = $data; $this->index = 0; } /** * Returns the number of items in current result * Implements Countable * * @return int */ public function count() { return count($this->data); } /** * Return the current result item * Implements Iterator * * @return Entity */ public function current() { $current = $this->data[$this->index]; return $this->service->get($current); } /** * Return the current result item key * Implements Iterator * * @return int|null */ public function key() { return $this->index; } /** * Move forward to next result item * Implements Iterator * */ public function next() { ++$this->index; } /** * Rewind the Iterator to the first result item * Implements Iterator * * @throws Exception\LdapException */ public function rewind() { $this->index = 0; } /** * Check if there is a current result item * after calls to rewind() or next() * Implements Iterator * * @return bool */ public function valid() { return isset($this->data[$this->index]); } } src/UnicaenLdap/Entity/Entity.php +323 Changes for src/UnicaenLdap/Entity/Entity.php: 323 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity; use UnicaenLdap\Node; use UnicaenLdap\Exception; use UnicaenLdap\Service\Service; /** * Classe mère des entrées de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ abstract class Entity { /** * Type d'entité * * @var string */ protected $type; /** * Service qui gère l'entité * * @var Service */ protected $service; /** * @var Node */ protected $node; /** * Liste des attributs contenant des dates * * @var string[] */ protected $dateTimeAttributes = array( ); public static function getNodeParams($type) { $params = array( 'Group' => array( 'cn', 'UnicaenLdap\\Entity\\Group' ), 'People' => array( 'uid', 'UnicaenLdap\\Entity\\People' ), ); if (! isset($params[$type])) throw new Exception('Paramètres de "'.$type.'" non trouvés'); return $params[$type]; } /** * Construit une entrée. * * @param Service $service Service qui gèrera la future entité * @param Node|Dn|array|string $data Noeud si Node, sinon DN */ public function __construct( Service $service, $data ) { $this->service = $service; if ($data instanceof Node){ $this->setNode( $data ); }else{ $this->setNode( Node::create($data) ); } } /** * Retourne le type du service * * @return string */ public function getType() { return $this->type; } /** * Retourne le service qui gère l'entité * * @return Service */ public function getService() { return $this->service; } /** * Retourne le nœud Ldap de base * * @return Node */ public function getNode() { return $this->node; } /** * Affecte un nœud de base * * @param Node $node */ public function setNode( Node $node ) { $this->node = $node; } /** * Retourne le Dn de l'entité sous forme de chaîne de caractères * * @return string */ public function getDn() { return $this->getNode()->getDnString(); } /** * Retourne la clé primaire correspondant à l'entité * * @return string */ public function getId() { $key = self::getNodeParams($this->type)[0]; return $this->get($key); } /** * Retourne la clé primaire correspondant à l'entité * * @return string */ public function getKey() { return self::getNodeParams($this->type)[0]; } /** * Retourne la liste des attributs de l'entité * * @return string[] */ public function getAttributesList() { return array_keys($this->getNode()->getAttributes()); } /** * Exporte sous forme de tableau le contenu de l'entité * * @return array */ public function toArray() { $result = array(); $attrsList = $this->getAttributesList(); foreach( $attrsList as $attrName ){ $result[$attrName] = $this->get($attrName); } return $result; } /** * Mise à jour de l'entité * * @return self */ public function update() { $this->getNode()->update(); return $this; } /** * Suppression de l'entité * * @return self */ public function delete() { $this->getNode()->delete(); return $this; } /** * Insertion de l'entité * * @return self */ public function insert() { $this->getNode()->attachLdap($this->service->getLdap()); return $this; } /** * Retourne un attribut * * @param string $attrName * @return mixed */ public function get($attrName) { if (in_array($attrName, $this->dateTimeAttributes)){ $value = $this->getNode()->getDateTimeAttribute($attrName); }else{ $value = $this->getNode()->getAttribute($attrName); } if (empty($value)){ $value = null; }elseif (1 == count($value)){ $value = $value[0]; } return $value; } /** * Affecte une nouvelle valeur à un attribut * * @param string $attrName * @param mixed $value * @return self */ public function set($attrName, $value) { if (in_array($attrName, $this->dateTimeAttributes)){ $this->getNode()->setDateTimeAttribute($attrName, $value); }else{ $this->getNode()->setAttribute($attrName, $value); } return $this; } /** * Retourne <code>true</code> si l'attribut $param possède la valeur $value, <code>false</code> sinon. * * @param string $attrName * @param mixed $value * @return boolean */ public function has($attrName, $value) { return $this->getNode()->attributeHasValue($attrName, $value); } /** * Ajoute une valeur à un attribut * * @param string $attrName * @param mixed $value * @return self */ public function add($attrName, $value) { if (in_array($attrName, $this->dateTimeAttributes)){ $this->getNode()->appendToDateTimeAttribute($attrName, $value); }else{ $this->getNode()->appendToAttribute($attrName, $value); } return $this; } /** * Retire une valeur à un attribut * * @param type $attrName * @param type $value * @return self */ public function remove($attrName, $value) { $this->getNode()->removeFromAttribute($attrName, $value); return $this; } /** * Méthode magique... * * @param string $attrName * @return mixed */ public function __get($attrName) { return $this->get($attrName); } /** * Méthode magique... * * @param string $attrName * @param mixed $value * @return self */ public function __set($attrName, $value) { return $this->set($attrName, $value); } /** * Methode magique ... * * @param string $method Nom de la méthode à appeler * @param array $arguments Tableau de paramètres * @return mixed */ public function __call($method, array $arguments) { $methods = array( 'get', 'set', 'has', 'add', 'remove' ); foreach( $methods as $methodName ){ if (0 === strpos($method, $methodName)){ $attrName = lcfirst(substr( $method, strlen($methodName) )); $arguments = array_merge( (array)$attrName, $arguments); return call_user_func_array(array($this,$methodName), $arguments ); } } } } No newline at end of file src/UnicaenLdap/Entity/Generic.php +21 Changes for src/UnicaenLdap/Entity/Generic.php: 21 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity; /** * Classe mère des adresses génériques de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class Generic extends Entity { protected $type = 'Generic'; /** * Liste des attributs contenant des dates * * @var string[] */ protected $dateTimeAttributes = array( ); } No newline at end of file src/UnicaenLdap/Entity/Group.php +63 Changes for src/UnicaenLdap/Entity/Group.php: 63 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity; use DateTime; /** * Classe mère des groupes de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class Group extends Entity { protected $type = 'Group'; /** * Liste des attributs contenant des dates * * @var string[] */ protected $dateTimeAttributes = array( 'supannGroupeDateFin', ); /** * Détermine si un groupe est valide ou non, c'est-à-dire si sa date de fin de validité n'est pas antérieure à la date testée * * @param DateTime $dateObservation */ public function isValid( DateTime $dateObservation = null ) { if (empty($dateObservation)) $dateObservation = new DateTime; $dateControle = $this->supannGroupeDateFin; return empty($dateControle) || ($dateControle >= $dateObservation->getTimestamp()); } /** * Détermine si un groupe est obsolète ou non, c'est-à-dire si sa date de fin de validité est antérieure à la date testée * * @param DateTime $dateObservation */ public function isObsolete( DateTime $dateObservation = null ) { return ! $this->isValid(); } /** * Retourne la liste des personnes membres du groupe * * @param string $orderBy Champ de tri (au besoin) * @return People[] */ public function getPeople( $orderBy=null ) { /* @var $people \UnicaenLdap\Service\People */ $people = $this->getService()->getServiceManager()->get('ldapServicePeople'); return $people->getAllBy( $this->get('member'), 'dn', $orderBy ); } } No newline at end of file Loading
Module.php +24 −3 Changes for Module.php: 24 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -50,10 +50,31 @@ class Module implements ConfigProviderInterface, ServiceProviderInterface */ public function getServiceConfig() { return array( 'factories' => array( $services = array( 'Generic', 'Group', 'People', 'Structure', 'System' ); $processus = array( ); $factories = array( 'ldap' => 'UnicaenLdap\LdapFactory', 'ldapOptions' => 'UnicaenLdap\Options\ModuleOptionsFactory', ), ); foreach( $services as $service ){ $factories['ldapService'.$service] = function($sm) use ($service){ $className = 'UnicaenLdap\\Service\\'.$service; return new $className; }; } foreach( $processus as $proc ){ $factories['ldapProcessus'.$proc] = function($sm) use ($proc){ $className = 'UnicaenLdap\\Processus\\'.$proc; return new $className; }; } return array( 'factories' => $factories, ); } }
src/UnicaenLdap/Collection.php +120 Changes for src/UnicaenLdap/Collection.php: 120 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap; use Countable; use Iterator; use UnicaenLdap\Service\Service; use UnicaenLdap\Entity\Entity; /** * Liste d'entités */ class Collection implements Iterator, Countable { /** * * * @var Service */ private $service; /** * Liste des identifiants à parcourir * * @var string[] */ private $data; /** * * @var integer */ private $index = 0; /** * Constructor. * * @param Service $service * @param string[] $data */ public function __construct( Service $service, array $data ) { $this->service = $service; $this->data = $data; $this->index = 0; } /** * Returns the number of items in current result * Implements Countable * * @return int */ public function count() { return count($this->data); } /** * Return the current result item * Implements Iterator * * @return Entity */ public function current() { $current = $this->data[$this->index]; return $this->service->get($current); } /** * Return the current result item key * Implements Iterator * * @return int|null */ public function key() { return $this->index; } /** * Move forward to next result item * Implements Iterator * */ public function next() { ++$this->index; } /** * Rewind the Iterator to the first result item * Implements Iterator * * @throws Exception\LdapException */ public function rewind() { $this->index = 0; } /** * Check if there is a current result item * after calls to rewind() or next() * Implements Iterator * * @return bool */ public function valid() { return isset($this->data[$this->index]); } }
src/UnicaenLdap/Entity/Entity.php +323 Changes for src/UnicaenLdap/Entity/Entity.php: 323 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity; use UnicaenLdap\Node; use UnicaenLdap\Exception; use UnicaenLdap\Service\Service; /** * Classe mère des entrées de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ abstract class Entity { /** * Type d'entité * * @var string */ protected $type; /** * Service qui gère l'entité * * @var Service */ protected $service; /** * @var Node */ protected $node; /** * Liste des attributs contenant des dates * * @var string[] */ protected $dateTimeAttributes = array( ); public static function getNodeParams($type) { $params = array( 'Group' => array( 'cn', 'UnicaenLdap\\Entity\\Group' ), 'People' => array( 'uid', 'UnicaenLdap\\Entity\\People' ), ); if (! isset($params[$type])) throw new Exception('Paramètres de "'.$type.'" non trouvés'); return $params[$type]; } /** * Construit une entrée. * * @param Service $service Service qui gèrera la future entité * @param Node|Dn|array|string $data Noeud si Node, sinon DN */ public function __construct( Service $service, $data ) { $this->service = $service; if ($data instanceof Node){ $this->setNode( $data ); }else{ $this->setNode( Node::create($data) ); } } /** * Retourne le type du service * * @return string */ public function getType() { return $this->type; } /** * Retourne le service qui gère l'entité * * @return Service */ public function getService() { return $this->service; } /** * Retourne le nœud Ldap de base * * @return Node */ public function getNode() { return $this->node; } /** * Affecte un nœud de base * * @param Node $node */ public function setNode( Node $node ) { $this->node = $node; } /** * Retourne le Dn de l'entité sous forme de chaîne de caractères * * @return string */ public function getDn() { return $this->getNode()->getDnString(); } /** * Retourne la clé primaire correspondant à l'entité * * @return string */ public function getId() { $key = self::getNodeParams($this->type)[0]; return $this->get($key); } /** * Retourne la clé primaire correspondant à l'entité * * @return string */ public function getKey() { return self::getNodeParams($this->type)[0]; } /** * Retourne la liste des attributs de l'entité * * @return string[] */ public function getAttributesList() { return array_keys($this->getNode()->getAttributes()); } /** * Exporte sous forme de tableau le contenu de l'entité * * @return array */ public function toArray() { $result = array(); $attrsList = $this->getAttributesList(); foreach( $attrsList as $attrName ){ $result[$attrName] = $this->get($attrName); } return $result; } /** * Mise à jour de l'entité * * @return self */ public function update() { $this->getNode()->update(); return $this; } /** * Suppression de l'entité * * @return self */ public function delete() { $this->getNode()->delete(); return $this; } /** * Insertion de l'entité * * @return self */ public function insert() { $this->getNode()->attachLdap($this->service->getLdap()); return $this; } /** * Retourne un attribut * * @param string $attrName * @return mixed */ public function get($attrName) { if (in_array($attrName, $this->dateTimeAttributes)){ $value = $this->getNode()->getDateTimeAttribute($attrName); }else{ $value = $this->getNode()->getAttribute($attrName); } if (empty($value)){ $value = null; }elseif (1 == count($value)){ $value = $value[0]; } return $value; } /** * Affecte une nouvelle valeur à un attribut * * @param string $attrName * @param mixed $value * @return self */ public function set($attrName, $value) { if (in_array($attrName, $this->dateTimeAttributes)){ $this->getNode()->setDateTimeAttribute($attrName, $value); }else{ $this->getNode()->setAttribute($attrName, $value); } return $this; } /** * Retourne <code>true</code> si l'attribut $param possède la valeur $value, <code>false</code> sinon. * * @param string $attrName * @param mixed $value * @return boolean */ public function has($attrName, $value) { return $this->getNode()->attributeHasValue($attrName, $value); } /** * Ajoute une valeur à un attribut * * @param string $attrName * @param mixed $value * @return self */ public function add($attrName, $value) { if (in_array($attrName, $this->dateTimeAttributes)){ $this->getNode()->appendToDateTimeAttribute($attrName, $value); }else{ $this->getNode()->appendToAttribute($attrName, $value); } return $this; } /** * Retire une valeur à un attribut * * @param type $attrName * @param type $value * @return self */ public function remove($attrName, $value) { $this->getNode()->removeFromAttribute($attrName, $value); return $this; } /** * Méthode magique... * * @param string $attrName * @return mixed */ public function __get($attrName) { return $this->get($attrName); } /** * Méthode magique... * * @param string $attrName * @param mixed $value * @return self */ public function __set($attrName, $value) { return $this->set($attrName, $value); } /** * Methode magique ... * * @param string $method Nom de la méthode à appeler * @param array $arguments Tableau de paramètres * @return mixed */ public function __call($method, array $arguments) { $methods = array( 'get', 'set', 'has', 'add', 'remove' ); foreach( $methods as $methodName ){ if (0 === strpos($method, $methodName)){ $attrName = lcfirst(substr( $method, strlen($methodName) )); $arguments = array_merge( (array)$attrName, $arguments); return call_user_func_array(array($this,$methodName), $arguments ); } } } } No newline at end of file
src/UnicaenLdap/Entity/Generic.php +21 Changes for src/UnicaenLdap/Entity/Generic.php: 21 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity; /** * Classe mère des adresses génériques de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class Generic extends Entity { protected $type = 'Generic'; /** * Liste des attributs contenant des dates * * @var string[] */ protected $dateTimeAttributes = array( ); } No newline at end of file
src/UnicaenLdap/Entity/Group.php +63 Changes for src/UnicaenLdap/Entity/Group.php: 63 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace UnicaenLdap\Entity; use DateTime; /** * Classe mère des groupes de l'annuaire LDAP. * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class Group extends Entity { protected $type = 'Group'; /** * Liste des attributs contenant des dates * * @var string[] */ protected $dateTimeAttributes = array( 'supannGroupeDateFin', ); /** * Détermine si un groupe est valide ou non, c'est-à-dire si sa date de fin de validité n'est pas antérieure à la date testée * * @param DateTime $dateObservation */ public function isValid( DateTime $dateObservation = null ) { if (empty($dateObservation)) $dateObservation = new DateTime; $dateControle = $this->supannGroupeDateFin; return empty($dateControle) || ($dateControle >= $dateObservation->getTimestamp()); } /** * Détermine si un groupe est obsolète ou non, c'est-à-dire si sa date de fin de validité est antérieure à la date testée * * @param DateTime $dateObservation */ public function isObsolete( DateTime $dateObservation = null ) { return ! $this->isValid(); } /** * Retourne la liste des personnes membres du groupe * * @param string $orderBy Champ de tri (au besoin) * @return People[] */ public function getPeople( $orderBy=null ) { /* @var $people \UnicaenLdap\Service\People */ $people = $this->getService()->getServiceManager()->get('ldapServicePeople'); return $people->getAllBy( $this->get('member'), 'dn', $orderBy ); } } No newline at end of file