Download the PHP package paweldecowski/ldap-dn without Composer
On this page you can find all versions of the php package paweldecowski/ldap-dn. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paweldecowski/ldap-dn
More information about paweldecowski/ldap-dn
Files in paweldecowski/ldap-dn
Package ldap-dn
Short Description Parse and manipulate LDAP Distinguished Names
License MIT
Informations about the package ldap-dn
LDAP DN
LDAP Distinguished Name parsing and manipulation library for PHP.
Table of contents
- Features
- Requirements
- Installation
- How to use
- Parsing DNs and accessing their components
- Create a DN object from a string
- Back to string representation
- Access RDNs by index
- Iterate RDNs
- Access attributes
- Multivalued RDNs
- Special characters
- Filter by attribute name
- Get the parent DN
- Manipulating DNs
- Remove a fragment of a DN
- Constructing DNs
- Exceptions
Features
- access individual RDNs by index
- iterate RDNs
- filter by attribute name
- support for escaping special characters
- access attribute values
- remove fragments of a DN
- construct DNs
- case-insensitive but case-preserving (lookups are case-insensitive but attribute names’ and values’ case is preserved)
- 100% test coverage
Requirements
- PHP 7.1
Installation
How to use
Parsing DNs and accessing their components
Create a DN object from a string
Back to string representation
Dn
class as well as classes representing its components (Rdn
, Attribute
) implement the __toString
method.
It means that in string context, they automatically become strings:
Access RDNs by index
Note that Rdn
s in a Dn
object are reversed in relation to the DN string (if read from left to right).
In a Dn
with n
Rdn
s, the right-most Rdn
is at index 0
and the left-most Rdn
is at index n-1
.
This is because it’s more natural and common to have the root object at index 0
.
Iterate RDNs
outputs:
Access attributes
If there’s only one instance of a certain attribute, you can get its value directly from the Dn
object:
If mulitiple attributes with the specified name are found, a MultipleAttributesReturnedException
is thrown.
Multivalued RDNs
Rdn
s are allowed to have multiple attributes, separated by the +
character. You can access them using array
dereferencing syntax.
You can also iterate attributes if you don’t know their names.
outputs:
Special characters
Filter by attribute name
Note that even though the result of filter()
is a Dn
object, it may not be a valid Distinguished Name (for example if you remove the root RDN).
This library doesn’t have the knowledge of your LDAP structure, so it can’t ensure validity.
Get the parent DN
Manipulating DNs
Dn
, Rdn
and Attribute
are immutable so all manipulation functions return a new object.
Remove a fragment of a DN
Sometimes you may want to remove a fragment of a DN, for example its base DN.
Constructing DNs
While the main purpose of the library is parsing DNs, you can also construct them.
Most RDNs contain a single attribute, so you can construct them with a shorthand syntax.
Exceptions
AttributeNotFoundException
Thrown if an attribute is not found in an Dn
.
DnNotFoundException
Thrown if an Dn
cannot be found in another Dn
InvalidAttributeStringException
Thrown if a string representing an attribute is malformed.
MultipleAttributesReturned exception
Thrown when multiple Attribute
s are returned when exactly 1 was expected.
NotImplementedException
Thrown when an unimplemented method is called.