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])
파일 보기 프로젝트 열기: horde/horde 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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