Commit 70b8f280 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚑 fix(ldap) Improve documentation

issue #1
parent 2a4f18e3
Pipeline #9007 passed with stages
in 16 seconds
......@@ -68,7 +68,7 @@ class Acl
/**
* Acl constructor
*
*
* @param string $acl The ACL string from LDAP
* @throws \FusionDirectory\Ldap\Exception
*/
......@@ -150,6 +150,11 @@ class Acl
}
}
/**
* Dump the ACL content to STDOUT
*
* @param string $indent String to add as a prefix to each line (usually spaces)
*/
public function dump (string $indent): void
{
echo $indent.$this->index.': to ';
......
......@@ -25,6 +25,9 @@ declare(strict_types = 1);
namespace FusionDirectory\Ldap;
/**
* Exception class thrown by \FusionDirectory\Ldap methods on errors
*/
class Exception extends \Exception
{
}
......@@ -28,7 +28,7 @@ namespace FusionDirectory\Ldap;
use DateTime, DateTimeZone;
/**
* LdapGeneralizedTime allows you to convert from and to LDAP GeneralizedTime format PHP DateTime objects
* Ldap\GeneralizedTime allows you to convert LDAP GeneralizedTime strings and PHP DateTime objects back and forth
*
* This class provides function to convert from LDAP GeneralizedTime to DateTime and the other way.
* Please note that leap seconds will be lost as PHP has no support for it (see https://bugs.php.net/bug.php?id=70335).
......
......@@ -58,7 +58,7 @@ class Link
/**
* Actually open the connection and bind to the LDAP server.
* Uses EXTERNAL for the bind.
*
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function bind (): void
......@@ -89,7 +89,7 @@ class Link
* @param array<string> $attrs Which attributes to fetch
* @param string $scope One of 'base','one' or 'subtree'
* @param array<array> $controls Controls to pass along with the search
*
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function search (string $basedn, string $filter, array $attrs = [], string $scope = 'subtree', array $controls = NULL): Result
......@@ -116,7 +116,7 @@ class Link
* @param string $dn The LDAP node to modify
* @param array<string,string|array<string>> $attrs The attributes values to add
* @param array<array> $controls Controls to send along with the request
*
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function mod_add (string $dn, array $attrs, array $controls = []): Result
......@@ -135,7 +135,7 @@ class Link
* @param string $dn The LDAP node to modify
* @param array<string,string|array<string>> $attrs The attributes values to replace
* @param array<array> $controls Controls to send along with the request
*
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function mod_replace (string $dn, array $attrs, array $controls = []): Result
......@@ -154,7 +154,7 @@ class Link
* @param string $dn The LDAP node to modify
* @param array<string,string|array<string>> $attrs The attributes values to delete
* @param array<array> $controls Controls to send along with the request
*
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function mod_del (string $dn, array $attrs, array $controls = []): Result
......@@ -172,7 +172,7 @@ class Link
*
* @param string $dn The LDAP node to delete
* @param array<array> $controls Controls to send along with the request
*
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function delete (string $dn, array $controls = []): Result
......@@ -186,9 +186,11 @@ class Link
}
/**
* @return array<string,array<string,string|true|array<string>>>
*
* @throws \FusionDirectory\Ldap\Exception
* Get exaustive list of object classes declared on the LDAP server
*
* @return array<string,array<string,string|true|array<string>>> List of object classes with their properties, indexed by name
*
* @throws \FusionDirectory\Ldap\Exception When an object class has no NAME or several
*/
public function getObjectClasses (): array
{
......@@ -219,7 +221,9 @@ class Link
}
/**
* @return array<string,string|true|array<string>>
* Parse an object class definition and returns its properties as an array
*
* @return array<string,string|true|array<string>> Array of properties
*/
public static function parseObjectClassDefinition (string $definition): array
{
......
......@@ -25,8 +25,16 @@ declare(strict_types = 1);
namespace FusionDirectory\Ldap;
/**
* Standard OID lists, with description and associated RFC number
*/
class OID
{
/**
* Standard controls OID list
*
* @var array<string,array<string|int>> Keys are OID, values are array with desc and rfc items
*/
public const CONTROLS = [
LDAP_CONTROL_MANAGEDSAIT => [
'desc' => 'Manage DSA IT',
......@@ -124,6 +132,11 @@ class OID
public const LDAP_EXOP_CANCEL = '1.3.6.1.1.8';
/**
* Standard extended operations OID list
*
* @var array<string,array<string|int>> Keys are OID, values are array with desc and rfc items
*/
public const EXOPS = [
LDAP_EXOP_START_TLS => [
'desc' => 'Start TLS',
......@@ -158,6 +171,11 @@ class OID
public const LDAP_FEATURE_LANGUAGETAG = '1.3.6.1.4.1.4203.1.5.4';
public const LDAP_FEATURE_RANGEMATCHING = '1.3.6.1.4.1.4203.1.5.5';
/**
* Standard features OID list
*
* @var array<string,array<string|int>> Keys are OID, values are array with desc and rfc items
*/
public const FEATURES = [
OID::LDAP_FEATURE_MODIFYINCREMENT => [
'desc' => 'Modify-Increment Extension',
......
......@@ -26,48 +26,60 @@ declare(strict_types = 1);
namespace FusionDirectory\Ldap;
/**
* Result of an Ldap operation
*
* @implements \Iterator<string,array<string,array<string>>>
*/
class Result implements \Iterator,\Countable
{
/**
* @var int
*/
* Error code
*
* @var int
*/
public $errcode;
/**
* @var string
*/
* Matched DN
*
* @var string
*/
public $matcheddn;
/**
* @var string
*/
* Error message
*
* @var string
*/
public $errmsg;
/**
* @var array<int>
*/
* Referrals list
*
* @var array<int>
*/
public $referrals;
/**
* @var array<array>
*/
* Controls list
*
* @var array<array>
*/
public $serverctrls;
/**
* @var resource
*/
* @var resource
*/
protected $link;
/**
* @var resource
*/
* @var resource
*/
protected $result;
/**
* @var resource|false
*/
* @var resource|false
*/
protected $cur;
/**
* @param resource $link
* @param resource $result
*
* @throws \FusionDirectory\Ldap\Exception
*
* @throws \FusionDirectory\Ldap\Exception When ldap_parse_result fails
*/
public function __construct ($link, $result)
{
......@@ -81,7 +93,7 @@ class Result implements \Iterator,\Countable
/**
* Assert that the result represents a successful LDAP operation, or throw an exception with the error message
*
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function assert (): void
......@@ -95,11 +107,19 @@ class Result implements \Iterator,\Countable
}
}
/**
* Count entries for a search result
*/
public function count (): int
{
return ldap_count_entries($this->link, $this->result);
}
/**
* Get current entry attributes as an associative array
*
* @return array<string, array<string>>
*/
public function current ()
{
assert(is_resource($this->cur));
......@@ -113,23 +133,37 @@ class Result implements \Iterator,\Countable
return $att;
}
/**
* Get the DN of current entry
*
* @return string
*/
public function key ()
{
assert(is_resource($this->cur));
return trim(ldap_get_dn($this->link, $this->cur));
}
/**
* Go to next entry
*/
public function next (): void
{
assert(is_resource($this->cur));
$this->cur = ldap_next_entry($this->link, $this->cur);
}
/**
* Rewind to first entry
*/
public function rewind (): void
{
$this->cur = ldap_first_entry($this->link, $this->result);
}
/**
* Whether there is a current entry
*/
public function valid (): bool
{
return is_resource($this->cur);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment