PHP Class LdapTools\Ldif\LdifParser

Author: Chad Sikorra ([email protected])
Show file Open project: ldaptools/ldaptools

Protected Properties

Property Type Description
$changeTypeMap A simple changetype to full class name mapping.
$commentQueue Any comments pending for the next entry in the LDIF.
$line The current line number we are on during parsing.
$lines string[]
$urlLoaders LdapTools\Ldif\UrlLoader\UrlLoaderInterface[] An array of UrlLoaders with the key set to the type of URL they handle.

Public Methods

Method Description
__construct ( )
hasUrlLoader ( string $type ) : boolean Check if a URL loader for a specific URL type exists.
parse ( string $ldif ) : Ldif Parses a string containing LDIF data and returns an object with the entries it contains.
removeUrlLoader ( string $type ) Remove a URL loader by its string type.
setUrlLoader ( string $type, LdapTools\Ldif\UrlLoader\UrlLoaderInterface $loader ) Set a URL loader to be used by the parser.

Protected Methods

Method Description
addCommentToQueueOrLdif ( Ldif $ldif ) Determine whether the comment should be added to the LDIF itself, or if it's a comment for an entry within the LDIF. If it's for an entry in the LDIF, then we make the assumption that we an empty line separates comments between the LDIF comments overall and the start of a comment for an entry. This seems like the most reasonable way to do it, though it still may not be perfect.
addDirectiveToEntry ( string $key, string $value, LdapTools\Ldif\Entry\LdifEntryInterface $entry ) Figures out what to add to the LDIF entry for a specific key/value directive given.
addModDnDirective ( LdifEntryModDn $entry, string $key, string $value )
addModifyDirective ( LdifEntryModify $entry, string $key, string $value )
cleanup ( ) Do a bit of cleanup post parsing.
currentLine ( ) : boolean | string
getBoolFromStringBool ( string $value ) : boolean Convert an expected string "true" or "false" to bool.
getBoolFromStringInt ( string $value ) : boolean Convert an expected string "0" or "1" to bool.
getContinuedValues ( $value ) : string Check for any continued values and concatenate them into one.
getKeyAndValue ( string $line ) : array
getLdapControl ( string $value ) : LdapControl Validate a control directive and get the value for the control and the criticality.
getLdifEntryObject ( string $dn, string $changeType ) : LdapTools\Ldif\Entry\LdifEntryInterface Get the LdifEntry for the changetype.
getValueFromUrl ( string $url ) : string Get the value of the URL data via a UrlLoader.
getValuesForModifyAction ( string $attribute, string $action ) : array
isComment ( ) : boolean Check if the current line is a comment.
isCommonDirective ( ) : boolean Check if the line is a directive common to any change type (ie. changetype or control).
isContinuedValue ( string $line ) : boolean Check if a line is a continuation of a previous value.
isEndOfEntry ( ) : boolean Check if we are at the end of a LDIF entry.
isEndOfLdif ( ) : boolean Check if we are at the end of the LDIF string.
isStartOfEntry ( ) : boolean Checks for the start of a LDIF entry on the current line.
nextLine ( boolean $advance = true ) : string | false
parseCommonDirectives ( $dn ) : LdapTools\Ldif\Entry\LdifEntryInterface Parses directives that are potentially common to all entries and returns the LdifEntry object. Common directives include: changetype, control
parseEntry ( ) : LdapTools\Ldif\Entry\LdifEntryInterface Parse an entry from the DN position until we reach the start of the next entry. Return the entry that was parsed.
setLdifVersion ( Ldif $ldif, integer $version )
setup ( string $ldif )
startsWith ( string $value, null | string $line = null ) : boolean Check if the current line starts with a specific value.
throwException ( string $message ) A simple helper to add additional information to the exception.
validateDirectiveInChange ( string $type, string $directive )

Method Details

__construct() public method

public __construct ( )

addCommentToQueueOrLdif() protected method

Determine whether the comment should be added to the LDIF itself, or if it's a comment for an entry within the LDIF. If it's for an entry in the LDIF, then we make the assumption that we an empty line separates comments between the LDIF comments overall and the start of a comment for an entry. This seems like the most reasonable way to do it, though it still may not be perfect.
protected addCommentToQueueOrLdif ( Ldif $ldif )
$ldif Ldif

addDirectiveToEntry() protected method

Figures out what to add to the LDIF entry for a specific key/value directive given.
protected addDirectiveToEntry ( string $key, string $value, LdapTools\Ldif\Entry\LdifEntryInterface $entry )
$key string
$value string
$entry LdapTools\Ldif\Entry\LdifEntryInterface

addModDnDirective() protected method

protected addModDnDirective ( LdifEntryModDn $entry, string $key, string $value )
$entry LdapTools\Ldif\Entry\LdifEntryModDn
$key string
$value string

addModifyDirective() protected method

protected addModifyDirective ( LdifEntryModify $entry, string $key, string $value )
$entry LdapTools\Ldif\Entry\LdifEntryModify
$key string
$value string

cleanup() protected method

Do a bit of cleanup post parsing.
protected cleanup ( )

currentLine() protected method

protected currentLine ( ) : boolean | string
return boolean | string

getBoolFromStringBool() protected method

Convert an expected string "true" or "false" to bool.
protected getBoolFromStringBool ( string $value ) : boolean
$value string
return boolean

getBoolFromStringInt() protected method

Convert an expected string "0" or "1" to bool.
protected getBoolFromStringInt ( string $value ) : boolean
$value string
return boolean

getContinuedValues() protected method

Check for any continued values and concatenate them into one.
protected getContinuedValues ( $value ) : string
$value
return string

getKeyAndValue() protected method

protected getKeyAndValue ( string $line ) : array
$line string
return array

getLdapControl() protected method

Validate a control directive and get the value for the control and the criticality.
protected getLdapControl ( string $value ) : LdapControl
$value string
return LdapTools\Connection\LdapControl

getLdifEntryObject() protected method

Get the LdifEntry for the changetype.
protected getLdifEntryObject ( string $dn, string $changeType ) : LdapTools\Ldif\Entry\LdifEntryInterface
$dn string
$changeType string
return LdapTools\Ldif\Entry\LdifEntryInterface

getValueFromUrl() protected method

Get the value of the URL data via a UrlLoader.
protected getValueFromUrl ( string $url ) : string
$url string
return string

getValuesForModifyAction() protected method

protected getValuesForModifyAction ( string $attribute, string $action ) : array
$attribute string
$action string
return array

hasUrlLoader() public method

Check if a URL loader for a specific URL type exists.
public hasUrlLoader ( string $type ) : boolean
$type string
return boolean

isComment() protected method

Check if the current line is a comment.
protected isComment ( ) : boolean
return boolean

isCommonDirective() protected method

Check if the line is a directive common to any change type (ie. changetype or control).
protected isCommonDirective ( ) : boolean
return boolean

isContinuedValue() protected method

Check if a line is a continuation of a previous value.
protected isContinuedValue ( string $line ) : boolean
$line string
return boolean

isEndOfEntry() protected method

Check if we are at the end of a LDIF entry.
protected isEndOfEntry ( ) : boolean
return boolean

isEndOfLdif() protected method

Check if we are at the end of the LDIF string.
protected isEndOfLdif ( ) : boolean
return boolean

isStartOfEntry() protected method

Checks for the start of a LDIF entry on the current line.
protected isStartOfEntry ( ) : boolean
return boolean

nextLine() protected method

protected nextLine ( boolean $advance = true ) : string | false
$advance boolean Whether to advance the currently active line ahead or not.
return string | false

parse() public method

Parses a string containing LDIF data and returns an object with the entries it contains.
public parse ( string $ldif ) : Ldif
$ldif string
return Ldif

parseCommonDirectives() protected method

Parses directives that are potentially common to all entries and returns the LdifEntry object. Common directives include: changetype, control
protected parseCommonDirectives ( $dn ) : LdapTools\Ldif\Entry\LdifEntryInterface
$dn
return LdapTools\Ldif\Entry\LdifEntryInterface

parseEntry() protected method

Parse an entry from the DN position until we reach the start of the next entry. Return the entry that was parsed.
protected parseEntry ( ) : LdapTools\Ldif\Entry\LdifEntryInterface
return LdapTools\Ldif\Entry\LdifEntryInterface

removeUrlLoader() public method

Remove a URL loader by its string type.
public removeUrlLoader ( string $type )
$type string

setLdifVersion() protected method

protected setLdifVersion ( Ldif $ldif, integer $version )
$ldif Ldif
$version integer

setUrlLoader() public method

Set a URL loader to be used by the parser.
public setUrlLoader ( string $type, LdapTools\Ldif\UrlLoader\UrlLoaderInterface $loader )
$type string The URL type (ie. file, http, etc)
$loader LdapTools\Ldif\UrlLoader\UrlLoaderInterface

setup() protected method

protected setup ( string $ldif )
$ldif string

startsWith() protected method

Check if the current line starts with a specific value.
protected startsWith ( string $value, null | string $line = null ) : boolean
$value string
$line null | string
return boolean

throwException() protected method

A simple helper to add additional information to the exception.
protected throwException ( string $message )
$message string

validateDirectiveInChange() protected method

protected validateDirectiveInChange ( string $type, string $directive )
$type string The changetype.
$directive string The directive used.

Property Details

$changeTypeMap protected property

A simple changetype to full class name mapping.
protected $changeTypeMap

$commentQueue protected property

Any comments pending for the next entry in the LDIF.
protected $commentQueue

$line protected property

The current line number we are on during parsing.
protected $line

$lines protected property

protected string[] $lines
return string[]

$urlLoaders protected property

An array of UrlLoaders with the key set to the type of URL they handle.
protected UrlLoaderInterface[],LdapTools\Ldif\UrlLoader $urlLoaders
return LdapTools\Ldif\UrlLoader\UrlLoaderInterface[]