Overview

Packages

  • Ldap

Classes

  • Horde_Ldap
  • Horde_Ldap_Entry
  • Horde_Ldap_Exception
  • Horde_Ldap_Filter
  • Horde_Ldap_Ldif
  • Horde_Ldap_RootDse
  • Horde_Ldap_Schema
  • Horde_Ldap_Search
  • Horde_Ldap_Util
  • Overview
  • Package
  • Class
  • Tree

Class Horde_Ldap_Ldif

LDIF capabilities for Horde_Ldap.

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";
    array_push($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-2012 Horde LLC (http://www.horde.org/)

Package: Ldap
Category: Horde
License: LGPL-3.0
Author: Benedikt Hallinger beni@php.net
Author: Jan Schneider jan@horde.org
See: http://www.ietf.org/rfc/rfc2849.txt
Located at Horde/Ldap/Ldif.php
Methods summary
public
# __construct( string|ressource $file, string $mode = 'r', array $options = array() )

Constructor.

Constructor.

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 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'

Parameters

$file
Filename or file handle.
$mode
<p>Mode to open the file, either 'r', 'w' or 'a'.</p>
$options
Options like described above.

Throws

Horde_Ldap_Exception
public Horde_Ldap_Entry
# readEntry( )

Reads one entry from the file and return it as a Horde_Ldap_Entry object.

Reads one entry from the file and return it as a Horde_Ldap_Entry object.

Returns

Horde_Ldap_Entry

Throws

Horde_Ldap_Exception
public boolean
# eof( )

Returns true when the end of the file is reached.

Returns true when the end of the file is reached.

Returns

boolean
public
# writeEntry( Horde_Ldap_Entry|array $entries )

Writes the entry or entries to the LDIF file.

Writes the entry or entries to the LDIF file.

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.

Parameters

$entries
Entry or array of entries.

Throws

Horde_Ldap_Exception
public
# writeVersion( )

Writes the version to LDIF.

Writes the version to LDIF.

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.

Throws

Horde_Ldap_Exception
public integer
# version( integer $version = null )

Returns or sets the LDIF version.

Returns or sets the LDIF 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.

Parameters

$version
LDIF version to set.

Returns

integer
The current or new version.

Throws

Horde_Ldap_Exception
public resource
# handle( )

Returns the file handle the Horde_Ldap_Ldif object reads from or writes to.

Returns the file handle the Horde_Ldap_Ldif object reads from or writes to.

You can, for example, use this to fetch the content of the LDIF file manually.

Returns

resource

Throws

Horde_Ldap_Exception
public
# done( )

Cleans up.

Cleans up.

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.

Throws

Horde_Ldap_Exception
public Horde_Ldap_Entry
# currentEntry( )

Returns the current Horde_Ldap_Entry object.

Returns the current Horde_Ldap_Entry object.

Returns

Horde_Ldap_Entry

Throws

Horde_Ldap_Exception
public Horde_Ldap_Entry
# parseLines( array $lines )

Parse LDIF lines of one entry into an Horde_Ldap_Entry object.

Parse LDIF lines of one entry into an Horde_Ldap_Entry object.

Parameters

$lines
LDIF lines for one entry.

Returns

Horde_Ldap_Entry
Horde_Ldap_Entry object for those lines.

Throws

Horde_Ldap_Exception
public array
# currentLines( )

Returns the lines that generated the current Horde_Ldap_Entry object.

Returns the lines that generated the current Horde_Ldap_Entry object.

Returns an empty array if no lines have been read so far.

Returns

array
Array of lines.
public array
# nextLines( boolean $force = false )

Returns the lines that will generate the next Horde_Ldap_Entry object.

Returns the lines that will generate the next Horde_Ldap_Entry object.

If you set $force to true you can iterate over the lines that build up entries manually. Otherwise, iterating is done using Horde_Ldap_Ldif::readEntry(). $force will move the file pointer forward, thus returning the next entry lines.

Wrapped lines will be unwrapped. Comments are stripped.

Parameters

$force
<p>Set this to true if you want to iterate over the lines manually</p>

Returns

array

Throws

Horde_Ldap_Exception
API documentation generated by ApiGen