Read and parse an LDIF file into Horde_Ldap_Entry objects
and print out the DNs. Store the entries for later use.
$entries = array();
$ldif = new Horde_Ldap_Ldif('test.ldif', 'r', $options);
do {
$entry = $ldif->readEntry();
$dn = $entry->dn();
echo " done building entry: $dn\n";
$entries[] = $entry;
} while (!$ldif->eof());
$ldif->done();
Write those entries to another file
$ldif = new Horde_Ldap_Ldif('test.out.ldif', 'w', $options);
$ldif->writeEntry($entries);
$ldif->done();
Copyright 2009 Benedikt Hallinger
Copyright 2010-2016 Horde LLC (http://www.horde.org/)
Показать файл
Открыть проект
Примеры использования класса
Свойство | Тип | Описание | |
---|---|---|---|
$_entrynum | integer | Counter for processed entries. | |
$_fh | resource | File handle for read/write. | |
$_fhOpened | boolean | Whether we opened the file handle ourselves. | |
$_inputLine | integer | Line counter for input file handle. | |
$_linesCur | array | Cache for lines that have built the current entry. | |
$_linesNext | array | Cache for lines that will build the next entry. | |
$_mode | string | Either 'r', 'a' or 'w' | |
$_options | array | Options. | |
$_versionWritten | boolean | Whether the LDIF version string was already written. |
Метод | Описание | |
---|---|---|
__construct ( string | ressource $file, string $mode = 'r', array $options = [] ) | Constructor. | |
currentEntry ( ) : Horde_Ldap_Entry | Returns the current Horde_Ldap_Entry object. | |
currentLines ( ) : array | Returns the lines that generated the current Horde_Ldap_Entry object. | |
done ( ) | Cleans up. | |
eof ( ) : boolean | Returns true when the end of the file is reached. | |
handle ( ) : resource | Returns the file handle the Horde_Ldap_Ldif object reads from or writes to. | |
nextLines ( boolean $force = false ) : array | Returns the lines that will generate the next Horde_Ldap_Entry object. | |
parseLines ( array $lines ) : Horde_Ldap_Entry | Parse LDIF lines of one entry into an Horde_Ldap_Entry object. | |
readEntry ( ) : Horde_Ldap_Entry | Reads one entry from the file and return it as a Horde_Ldap_Entry object. | |
version ( integer $version = null ) : integer | Returns or sets the LDIF version. | |
writeEntry ( Horde_Ldap_Entry | array $entries ) | Writes the entry or entries to the LDIF file. | |
writeVersion ( ) | Writes the version to LDIF. |
Метод | Описание | |
---|---|---|
_changeEntry ( Horde_Ldap_Entry $entry ) | Writes an LDIF file that describes an entry change. | |
_convertAttribute ( string $attr_name, string $attr_value ) : string | Converts an attribute and value to LDIF string representation. | |
_convertDN ( string $dn ) : string | Converts an entry's DN to LDIF string representation. | |
_finishEntry ( ) | Finishes an LDIF entry. | |
_isBinary ( string $value ) : boolean | Returns whether some data is considered binary and must be base64-encoded. | |
_writeAttribute ( string $attr_name, string | array $attr_values ) | Writes an attribute to the file handle. | |
_writeDN ( string $dn ) | Writes a DN to the file handle. | |
_writeEntry ( Horde_Ldap_Entry $entry ) | Writes an LDIF file that describes an entry. | |
_writeLine ( string $line, string $error = 'Unable to write to file handle' ) | Writes an arbitary line to the file handle. |
protected _changeEntry ( Horde_Ldap_Entry $entry ) | ||
$entry | Horde_Ldap_Entry |
protected _convertDN ( string $dn ) : string | ||
$dn | string | UTF8 encoded DN. |
Результат | string | LDIF string for that DN. |
protected _writeEntry ( Horde_Ldap_Entry $entry ) | ||
$entry | Horde_Ldap_Entry |
protected _writeLine ( string $line, string $error = 'Unable to write to file handle' ) | ||
$line | string | Content to write. |
$error | string | If error occurs, throw this exception message. |
public currentEntry ( ) : Horde_Ldap_Entry | ||
Результат | Horde_Ldap_Entry |
public currentLines ( ) : array | ||
Результат | array | Array of lines. |
public done ( ) |
public handle ( ) : resource | ||
Результат | resource |
public parseLines ( array $lines ) : Horde_Ldap_Entry | ||
$lines | array | LDIF lines for one entry. |
Результат | Horde_Ldap_Entry | Horde_Ldap_Entry object for those lines. |
public readEntry ( ) : Horde_Ldap_Entry | ||
Результат | Horde_Ldap_Entry |
public writeEntry ( Horde_Ldap_Entry | array $entries ) | ||
$entries | Horde_Ldap_Entry | array | Entry or array of entries. |
public writeVersion ( ) |
protected int $_entrynum | ||
Результат | integer |
protected bool $_fhOpened | ||
Результат | boolean |
protected int $_inputLine | ||
Результат | integer |
protected array $_linesCur | ||
Результат | array |
protected array $_linesNext | ||
Результат | array |
protected bool $_versionWritten | ||
Результат | boolean |