Net_LDAP
[ class tree: Net_LDAP ] [ index: Net_LDAP ] [ all elements ]

Class: Net_LDAP_LDIF

Source Location: /Net_LDAP-1.1.5/LDAP/LDIF.php

Class Overview

PEAR
   |
   --Net_LDAP_LDIF

LDIF capabilitys for Net_LDAP, closely taken from PERLs Net::LDAP


Author(s):

Methods


Inherited Variables

Inherited Methods


Class Details

[line 63]
LDIF capabilitys for Net_LDAP, closely taken from PERLs Net::LDAP

It provides a means to convert between Net_LDAP_Entry objects and LDAP entries represented in LDIF format files. Reading and writing are supported and may manipulate single entries or lists of entries.

Usage example:

  1.  // Read and parse an ldif-file into Net_LDAP_Entry objects
  2.  // and print out the DNs. Store the entries for later use.
  3.  require 'Net/LDAP/LDIF.php';
  4.  $options = array(
  5.        'onerror' => 'die'
  6.  );
  7.  $entries = array();
  8.  $ldif = new Net_LDAP_LDIF('test.ldif''r'$options);
  9.  do {
  10.        $entry $ldif->read_entry();
  11.        $dn    $entry->dn();
  12.        echo " done building entry: $dn\n";
  13.        array_push($entries$entry);
  14.  while (!$ldif->eof());
  15.  $ldif->done();
  16.  
  17.  
  18.  // write those entries to another file
  19.  $ldif = new Net_LDAP_LDIF('test.out.ldif''w'$options);
  20.  $ldif->write_entry($entries);
  21.  $ldif->done();



[ Top ]


Method Detail

Net_LDAP_LDIF (Constructor)   [line 218]

Net_LDAP_LDIF Net_LDAP_LDIF( string|ressource $file, [string $mode = 'r'], [array $options = array()])

Open LDIF file for reading or for writing

new (FILE): Open the file read-only. FILE may be the name of a file or an already open filehandle. If the file doesn't exist, it will be created if in write mode.

new (FILE, MODE, OPTIONS): Open the file with the given MODE (see PHPs fopen()), eg "w" or "a". FILE may be the name of a file or an already open filehandle. PERLs Net_LDAP "FILE|" mode does not work curently.

OPTIONS is an associative array and may contain: encode => 'none' | 'canonical' | 'base64' Some DN values in LDIF cannot be written verbatim and have to be encoded in some way: 'none' No encoding. 'canonical' See "canonical_dn()" in Net::LDAP::Util. 'base64' Use base64. (default, this differs from the Perl interface. The perl default is "none"!)

onerror => 'die' | 'warn' | undef Specify what happens when an error is detected. 'die' Net_LDAP_LDIF will croak with an appropriate message. 'warn' Net_LDAP_LDIF will warn (echo) with an appropriate message. undef Net_LDAP_LDIF will not warn (default), use error().

change => 1 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.

lowercase => 1 Convert attribute names to lowercase when writing.

sort => 1 Sort attribute names when writing entries according to the rule: objectclass first then all other attributes alphabetically sorted by attribute name

version => '1' 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 Net_LDAP_LDIF tries to adhere more strictly to the LDIF specification in RFC2489 in a few places. The default is undef meaning no version information is written to the LDIF file.

wrap => 78 Number of columns where output line wrapping shall occur. Default is 78. Setting it to 40 or lower inhibits wrapping.

[NOT IMPLEMENTED] raw => REGEX Use REGEX 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:

string|ressource   $file     Filename or filehandle
string   $mode     Mode to open filename
array   $options     Options like described above

[ Top ]

current_entry   [line 539]

Net_LDAP_Entry|false current_entry( )

Returns the current Net::LDAP::Entry object.

[ Top ]

current_lines   [line 612]

array current_lines( )

Returns the lines that generated the current Net::LDAP::Entry object.

Note that this returns an empty array if no lines have been read so far.

  • Return: Array of lines

[ Top ]

done   [line 484]

void done( )

Clean 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 Net_LDAP_LDIF.


[ Top ]

eof   [line 306]

boolean eof( )

Returns true when the end of the file is reached.

[ Top ]

error   [line 512]

false|Net_LDAP_Error error( [boolean $as_string = false])

Returns last error message if error was found.

Example:

  1.   $ldif->someAction();
  2.   if ($ldif->error()) {
  3.      echo "Error: ".$ldif->error()." at input line: ".$ldif->error_lines();
  4.   }


Parameters:

boolean   $as_string     If set to true, only the message is returned

[ Top ]

error_lines   [line 529]

int error_lines( )

Returns lines that resulted in error.

Perl returns an array of faulty lines in list context, but we always just return an int because of PHPs language.


[ Top ]

handle   [line 464]

null|resource &handle( )

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

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


[ Top ]

next_lines   [line 630]

array next_lines( [boolean $force = false])

Returns the lines that will generate the next Net::LDAP::Entry object.

If you set $force to TRUE then you can iterate over the lines that build up entries manually. Otherwise, iterating is done using read_entry(). Force will move the file pointer forward, thus returning the next entries lines.

Wrapped lines will be unwrapped. Comments are stripped.


Parameters:

boolean   $force     Set this to true if you want to iterate over the lines manually

[ Top ]

parseLines   [line 552]

Net_LDAP_Entry|false parseLines( array $lines)

Parse LDIF lines of one entry into an Net_LDAP_Entry object
  • Return: Net_LDAP_Entry object for those lines
  • Todo: what about file inclusions and urls? "jpegphoto:< file:///usr/local/directory/photos/fiona.jpg"

Parameters:

array   $lines     LDIF lines for one entry

[ Top ]

read_entry   [line 291]

Net_LDAP_Entry read_entry( )

Read one entry from the file and return it as a Net::LDAP::Entry object.

[ Top ]

version   [line 445]

int version( [int $version = null])

Get or set LDIF version

If called without arguments it returns the version of the LDIF file or undef if no version has been set. If called with an argument it sets the LDIF version to VERSION. According to RFC 2849 currently the only legal value for VERSION is 1.


Parameters:

int   $version     (optional) LDIF version to set

[ Top ]

write_entry   [line 323]

void write_entry( Net_LDAP_Entry|array $entries)

Write the entry or entries to the LDIF file.

If you want to build an LDIF file containing several entries AND you want to call write_entry() several times, you must open the filehandle in append mode ("a"), otherwise you will always get the last entry only.

  • Todo: implement operations on whole entries (adding a whole entry)

Parameters:

Net_LDAP_Entry|array   $entries     Entry or array of entries

[ Top ]

write_version   [line 428]

void write_version( )

Write 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.


[ Top ]


Documentation generated on Fri, 03 Jul 2009 11:00:08 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.