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

Class: Net_LDAP2_LDIF

Source Location: /Net_LDAP2-2.2.0/Net/LDAP2/LDIF.php

Class Overview

PEAR
   |
   --Net_LDAP2_LDIF

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


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 66]
LDIF capabilitys for Net_LDAP2, closely taken from PERLs Net::LDAP

It provides a means to convert between Net_LDAP2_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_LDAP2_Entry objects
  2.  // and print out the DNs. Store the entries for later use.
  3.  require 'Net/LDAP2/LDIF.php';
  4.  $options = array(
  5.        'onerror' => 'die'
  6.  );
  7.  $entries = array();
  8.  $ldif = new Net_LDAP2_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_LDAP2_LDIF('test.out.ldif''w'$options);
  20.  $ldif->write_entry($entries);
  21.  $ldif->done();



[ Top ]


Class Variables

$_entrynum =  0

[line 124]

counter for processed entries
  • Access: protected

Type:   int


[ Top ]

$_error = array('error' => null,
                              'line'  => 0
                             )

[line 90]

Errorcache
  • Access: protected

Type:   array


[ Top ]

$_FH =  null

[line 100]

Filehandle for read/write
  • Access: protected

Type:   array


[ Top ]

$_FH_opened =  false

[line 108]

Says, if we opened the filehandle ourselves
  • Access: protected

Type:   array


[ Top ]

$_input_line =  0

[line 116]

Linecounter for input file handle
  • Access: protected

Type:   array


[ Top ]

$_lines_cur = array()

[line 150]

Cache for lines that have build the current entry
  • Access: protected

Type:   boolean


[ Top ]

$_lines_next = array()

[line 158]

Cache for lines that will build the next entry
  • Access: protected

Type:   boolean


[ Top ]

$_mode =  false

[line 134]

Mode we are working in

Either 'r', 'a' or 'w'

  • Access: protected

Type:   string


[ Top ]

$_options = array('encode'    => 'base64',
                                'onerror'   => null,
                                'change'    => 0,
                                'lowercase' => 0,
                                'sort'      => 0,
                                'version'   => null,
                                'wrap'      => 78,
                                'raw'       => ''
                               )

[line 74]

Options
  • Access: protected

Type:   array


[ Top ]

$_version_written =  false

[line 142]

Tells, if the LDIF version string was already written
  • Access: protected

Type:   boolean


[ Top ]



Method Detail

__construct (Constructor)   [line 219]

Net_LDAP2_LDIF __construct( 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_LDAP2 "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' | NULL Specify what happens when an error is detected. 'die' Net_LDAP2_LDIF will croak with an appropriate message. 'warn' Net_LDAP2_LDIF will warn (echo) with an appropriate message. NULL Net_LDAP2_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_LDAP2_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 => 78 Number of columns where output line wrapping shall occur. Default is 78. Setting it to 40 or lower inhibits wrapping.

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"

  • Access: public

Parameters:

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

[ Top ]

convertAttribute   [line 738]

string convertAttribute( string $attr_name, string $attr_value)

Convert an attribute and value to LDIF string representation

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.

  • Return: LDIF string for that attribute and value
  • Access: protected

Parameters:

string   $attr_name   —  Name of the attribute
string   $attr_value   —  Value of the attribute

[ Top ]

convertDN   [line 800]

string convertDN( string $dn)

Convert an entries DN to LDIF string representation

It honors correct encoding of values according to RFC 2849.

  • Return: LDIF string for that DN
  • Todo: I am not sure, if the UTF8 stuff is correctly handled right now
  • Access: protected

Parameters:

string   $dn   —  UTF8-Encoded DN

[ Top ]

current_entry   [line 541]

Net_LDAP2_Entry|false current_entry( )

Returns the current Net::LDAP::Entry object.
  • Access: public

[ Top ]

current_lines   [line 613]

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
  • Access: public

[ Top ]

done   [line 486]

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

  • Access: public

[ Top ]

dropError   [line 913]

void dropError( string $msg, [int $line = null])

Optionally raises an error and pushes the error on the error cache
  • Access: protected

Parameters:

string   $msg   —  Errortext
int   $line   —  Line in the LDIF that caused the error

[ Top ]

eof   [line 307]

boolean eof( )

Returns true when the end of the file is reached.
  • Access: public

[ Top ]

error   [line 514]

false|Net_LDAP2_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.   }

  • Access: public

Parameters:

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

[ Top ]

error_lines   [line 531]

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.

  • Access: public

[ Top ]

finishEntry   [line 880]

void finishEntry( )

Finishes an LDIF entry
  • Access: protected

[ Top ]

handle   [line 466]

null|resource &handle( )

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

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

  • Access: public

[ Top ]

next_lines   [line 631]

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.

  • Access: public

Parameters:

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

[ Top ]

parseLines   [line 554]

Net_LDAP2_Entry|false parseLines( array $lines)

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

Parameters:

array   $lines   —  LDIF lines for one entry

[ Top ]

read_entry   [line 292]

Net_LDAP2_Entry read_entry( )

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

[ Top ]

version   [line 447]

int version( [int $version = null])

Get or set LDIF version

If called without arguments it returns the version of the LDIF file or NULL 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.

  • Access: public

Parameters:

int   $version   —  (optional) LDIF version to set

[ Top ]

writeAttribute   [line 841]

void writeAttribute( string $attr_name, string|array $attr_values)

Writes an attribute to the filehandle
  • Access: protected

Parameters:

string   $attr_name   —  Name of the attribute
string|array   $attr_values   —  Single attribute value or array with attribute values

[ Top ]

writeDN   [line 861]

void writeDN( string $dn)

Writes a DN to the filehandle
  • Access: protected

Parameters:

string   $dn   —  DN to write

[ Top ]

writeLine   [line 894]

true|false writeLine( string $line, [string $error = 'Net_LDAP2_LDIF error: unable to write to filehandle'])

Just write an arbitary line to the filehandle
  • Access: protected

Parameters:

string   $line   —  Content to write
string   $error   —  If error occurs, drop this message

[ Top ]

write_entry   [line 324]

void write_entry( Net_LDAP2_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)
  • Access: public

Parameters:

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

  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 16:03:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.