PHP Класс Horde_Ldap_Ldif, horde

This class provides a means to convert between Horde_Ldap_Entry objects and LDAP entries represented in LDIF format files. Reading and writing are supported and manipulating of single entries or lists of entries. Usage example: 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/)
См. также: http://www.ietf.org/rfc/rfc2849.txt
Автор: Benedikt Hallinger ([email protected])
Автор: Jan Schneider ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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.

Описание методов

__construct() публичный Метод

Opens an LDIF file for reading or writing. $options is an associative array and may contain: - 'encode' (string): Some DN values in LDIF cannot be written verbatim and have to be encoded in some way. Possible values: - 'none': No encoding. - 'canonical': See {@link Horde_Ldap_Util::canonicalDN()}. - 'base64': Use base64 (default). - 'change' (boolean): Write entry changes to the LDIF file instead of the entries itself. I.e. write LDAP operations acting on the entries to the file instead of the entries contents. This writes the changes usually carried out by an update() to the LDIF file. Defaults to false. - 'lowercase' (boolean): Convert attribute names to lowercase when writing. Defaults to false. - 'sort' (boolean): Sort attribute names when writing entries according to the rule: objectclass first then all other attributes alphabetically sorted by attribute name. Defaults to false. - 'version' (integer): Set the LDIF version to write to the resulting LDIF file. According to RFC 2849 currently the only legal value for this option is 1. When this option is set Horde_Ldap_Ldif tries to adhere more strictly to the LDIF specification in RFC2489 in a few places. The default is null meaning no version information is written to the LDIF file. - 'wrap' (integer): Number of columns where output line wrapping shall occur. Default is 78. Setting it to 40 or lower inhibits wrapping. - 'raw' (string): Regular expression to denote the names of attributes that are to be considered binary in search results if writing entries. Example: 'raw' => '/(?i:^jpegPhoto|;binary)/i'
public __construct ( string | ressource $file, string $mode = 'r', array $options = [] )
$file string | ressource Filename or file handle.
$mode string Mode to open the file, either 'r', 'w' or 'a'.
$options array Options like described above.

_changeEntry() защищенный Метод

Writes an LDIF file that describes an entry change.
protected _changeEntry ( Horde_Ldap_Entry $entry )
$entry Horde_Ldap_Entry

_convertAttribute() защищенный Метод

It honors correct encoding of values according to RFC 2849. Line wrapping will occur at the configured maximum but only if the value is greater than 40 chars.
protected _convertAttribute ( string $attr_name, string $attr_value ) : string
$attr_name string Name of the attribute.
$attr_value string Value of the attribute.
Результат string LDIF string for that attribute and value.

_convertDN() защищенный Метод

It honors correct encoding of values according to RFC 2849.
protected _convertDN ( string $dn ) : string
$dn string UTF8 encoded DN.
Результат string LDIF string for that DN.

_finishEntry() защищенный Метод

Finishes an LDIF entry.
protected _finishEntry ( )

_isBinary() защищенный Метод

Returns whether some data is considered binary and must be base64-encoded.
protected _isBinary ( string $value ) : boolean
$value string Some data.
Результат boolean True if the data should be encoded.

_writeAttribute() защищенный Метод

Writes an attribute to the file handle.
protected _writeAttribute ( string $attr_name, string | array $attr_values )
$attr_name string Name of the attribute.
$attr_values string | array Single attribute value or array with attribute values.

_writeDN() защищенный Метод

Writes a DN to the file handle.
protected _writeDN ( string $dn )
$dn string DN to write.

_writeEntry() защищенный Метод

Writes an LDIF file that describes an entry.
protected _writeEntry ( Horde_Ldap_Entry $entry )
$entry Horde_Ldap_Entry

_writeLine() защищенный Метод

Writes an arbitary line to the file handle.
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.

currentEntry() публичный Метод

Returns the current Horde_Ldap_Entry object.
public currentEntry ( ) : Horde_Ldap_Entry
Результат Horde_Ldap_Entry

currentLines() публичный Метод

Returns an empty array if no lines have been read so far.
public currentLines ( ) : array
Результат array Array of lines.

done() публичный Метод

This method signals that the LDIF object is no longer needed. You can use this to free up some memory and close the file handle. The file handle is only closed, if it was opened from Horde_Ldap_Ldif.
public done ( )

eof() публичный Метод

Returns true when the end of the file is reached.
public eof ( ) : boolean
Результат boolean

handle() публичный Метод

You can, for example, use this to fetch the content of the LDIF file manually.
public handle ( ) : resource
Результат resource

nextLines() публичный Метод

If you set $force to true you can iterate over the lines that build up entries manually. Otherwise, iterating is done using {@link readEntry()}. $force will move the file pointer forward, thus returning the next entry lines. Wrapped lines will be unwrapped. Comments are stripped.
public nextLines ( boolean $force = false ) : array
$force boolean Set this to true if you want to iterate over the lines manually
Результат array

parseLines() публичный Метод

Parse LDIF lines of one entry into an Horde_Ldap_Entry object.
public parseLines ( array $lines ) : Horde_Ldap_Entry
$lines array LDIF lines for one entry.
Результат Horde_Ldap_Entry Horde_Ldap_Entry object for those lines.

readEntry() публичный Метод

Reads one entry from the file and return it as a Horde_Ldap_Entry object.
public readEntry ( ) : Horde_Ldap_Entry
Результат Horde_Ldap_Entry

version() публичный Метод

If called with an argument it sets the LDIF version. According to RFC 2849 currently the only legal value for the version is 1.
public version ( integer $version = null ) : integer
$version integer LDIF version to set.
Результат integer The current or new version.

writeEntry() публичный Метод

If you want to build an LDIF file containing several entries AND you want to call writeEntry() several times, you must open the file handle in append mode ('a'), otherwise you will always get the last entry only.
public writeEntry ( Horde_Ldap_Entry | array $entries )
$entries Horde_Ldap_Entry | array Entry or array of entries.

writeVersion() публичный Метод

If the object's version is defined, this method allows to explicitely write the version before an entry is written. If not called explicitely, it gets called automatically when writing the first entry.
public writeVersion ( )

Описание свойств

$_entrynum защищенное свойство

Counter for processed entries.
protected int $_entrynum
Результат integer

$_fh защищенное свойство

File handle for read/write.
protected resource $_fh
Результат resource

$_fhOpened защищенное свойство

Whether we opened the file handle ourselves.
protected bool $_fhOpened
Результат boolean

$_inputLine защищенное свойство

Line counter for input file handle.
protected int $_inputLine
Результат integer

$_linesCur защищенное свойство

Cache for lines that have built the current entry.
protected array $_linesCur
Результат array

$_linesNext защищенное свойство

Cache for lines that will build the next entry.
protected array $_linesNext
Результат array

$_mode защищенное свойство

Either 'r', 'a' or 'w'
protected string $_mode
Результат string

$_options защищенное свойство

Options.
protected array $_options
Результат array

$_versionWritten защищенное свойство

Whether the LDIF version string was already written.
protected bool $_versionWritten
Результат boolean