1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect3 id="zend.ldap.api.reference.zend-ldap-dn">
4 <title>Zend_Ldap_Dn</title>
7 <classname>Zend_Ldap_Dn</classname> provides an object-oriented interface to
8 manipulating <acronym>LDAP</acronym> distinguished names (DN). The parameter
9 <varname>$caseFold</varname> that is used in several methods determines the way DN
10 attributes are handled regarding their case. Allowed values for this paraneter are:
15 <term><constant>Zend_Ldap_Dn::ATTR_CASEFOLD_NONE</constant></term>
16 <listitem><para>No case-folding will be done.</para></listitem>
20 <term><constant>Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER</constant></term>
21 <listitem><para>All attributes will be converted to upper-case.</para></listitem>
25 <term><constant>Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER</constant></term>
26 <listitem><para>All attributes will be converted to lower-case.</para></listitem>
31 The default case-folding is <constant>Zend_Ldap_Dn::ATTR_CASEFOLD_NONE</constant> and
32 can be set with <methodname>Zend_Ldap_Dn::setDefaultCaseFold()</methodname>. Each instance
33 of <classname>Zend_Ldap_Dn</classname> can have its own case-folding-setting. If the
34 <varname>$caseFold</varname> parameter is ommitted in method-calls it defaults to the
35 instance's case-folding setting.
39 The class implements <code>ArrayAccess</code> to allow indexer-access to the
40 different parts of the DN. The <code>ArrayAccess</code>-methods proxy to
41 <methodname>Zend_Ldap_Dn::get($offset, 1, null)</methodname> for <code>offsetGet(integer
42 $offset)</code>, to <methodname>Zend_Ldap_Dn::set($offset, $value)</methodname> for
43 <methodname>offsetSet()</methodname> and to
44 <methodname>Zend_Ldap_Dn::remove($offset, 1)</methodname> for
45 <methodname>offsetUnset()</methodname>. <methodname>offsetExists()</methodname> simply
46 checks if the index is within the bounds.
49 <table id="zend.ldap.api.reference.zend-ldap-dn.table">
50 <title>Zend_Ldap_Dn API</title>
56 <entry>Description</entry>
63 <emphasis><code>Zend_Ldap_Dn factory(string|array $dn,
64 string|null $caseFold)</code> </emphasis>
68 Creates a <classname>Zend_Ldap_Dn</classname> instance from an array
69 or a string. The array must conform to the array structure detailed
70 under <methodname>Zend_Ldap_Dn::implodeDn()</methodname>.
76 <emphasis><code>Zend_Ldap_Dn fromString(string $dn,
77 string|null $caseFold)</code> </emphasis>
81 Creates a <classname>Zend_Ldap_Dn</classname> instance from a
88 <emphasis><code>Zend_Ldap_Dn fromArray(array $dn,
89 string|null $caseFold)</code> </emphasis>
93 Creates a <classname>Zend_Ldap_Dn</classname> instance from an array.
94 The array must conform to the array structure detailed under
95 <methodname>Zend_Ldap_Dn::implodeDn()</methodname>.
100 <entry><code>array getRdn(string|null $caseFold)</code></entry>
103 Gets the <acronym>RDN</acronym> of the current DN. The return value is an
104 array with the <acronym>RDN</acronym> attribute names its keys and the
105 <acronym>RDN</acronym> attribute values.
110 <entry><code>string getRdnString(string|null $caseFold)</code></entry>
113 Gets the <acronym>RDN</acronym> of the current DN. The return value is a
119 <entry><code>Zend_Ldap_Dn getParentDn(integer $levelUp)</code></entry>
122 Gets the DN of the current DN's ancestor
123 <varname>$levelUp</varname> levels up the tree. <varname>$levelUp</varname>
124 defaults to <code>1</code>.
130 <code>array get(integer $index, integer $length, string|null
135 Returns a slice of the current DN determined by
136 <varname>$index</varname> and <varname>$length</varname>.
137 <varname>$index</varname> starts with <code>0</code> on the DN part from the
143 <entry><code>Zend_Ldap_Dn set(integer $index, array $value)</code></entry>
146 Replaces a DN part in the current DN. This operation
147 manipulates the current instance.
152 <entry><code>Zend_Ldap_Dn remove(integer $index, integer $length)</code></entry>
155 Removes a DN part from the current DN. This operation
156 manipulates the current instance. <varname>$length</varname> defaults to
162 <entry><code>Zend_Ldap_Dn append(array $value)</code></entry>
165 Appends a DN part to the current DN. This operation
166 manipulates the current instance.
171 <entry><code>Zend_Ldap_Dn prepend(array $value)</code></entry>
174 Prepends a DN part to the current DN. This operation
175 manipulates the current instance.
180 <entry><code>Zend_Ldap_Dn insert(integer $index, array $value)</code></entry>
183 Inserts a DN part after the index <varname>$index</varname> to the
184 current DN. This operation manipulates the current
190 <entry><code>void setCaseFold(string|null $caseFold)</code></entry>
193 Sets the case-folding option to the current DN instance. If
194 <varname>$caseFold</varname> is <constant>NULL</constant> the default
195 case-folding setting (<constant>Zend_Ldap_Dn::ATTR_CASEFOLD_NONE</constant>
196 by default or set via
197 <methodname>Zend_Ldap_Dn::setDefaultCaseFold()</methodname> will be set for
198 the current instance.
203 <entry><code>string toString(string|null $caseFold)</code></entry>
204 <entry>Returns DN as a string.</entry>
208 <entry><code>array toArray(string|null $caseFold)</code></entry>
209 <entry>Returns DN as an array.</entry>
213 <entry><code>string __toString()</code></entry>
216 Returns DN as a string - proxies to
217 <methodname>Zend_Ldap_Dn::toString(null)</methodname>.
223 <emphasis><code>void setDefaultCaseFold(string
224 $caseFold)</code> </emphasis>
228 Sets the default case-folding option used by all instances
229 on creation by default. Already existing instances are not affected
236 <emphasis><code>array escapeValue(string|array
237 $values)</code> </emphasis>
240 <entry>Escapes a DN value according to <acronym>RFC</acronym> 2253.</entry>
245 <emphasis><code>array unescapeValue(string|array
246 $values)</code> </emphasis>
250 Undoes the conversion done by
251 <methodname>Zend_Ldap_Dn::escapeValue()</methodname>.
257 <emphasis><code>array explodeDn(string $dn, array
258 &$keys, array &$vals, string|null $caseFold)</code>
264 Explodes the DN <varname>$dn</varname> into an array containing
265 all parts of the given DN. <varname>$keys</varname> optinally receive DN
266 keys (e.g. CN, OU, DC, ...). <varname>$vals</varname> optionally receive
267 DN values. The resulting array will be of type
270 <programlisting language="php"><![CDATA[
272 array("cn" => "name1", "uid" => "user"),
273 array("cn" => "name2"),
274 array("dc" => "example"),
280 for a DN of <code>cn=name1+uid=user,cn=name2,dc=example,dc=org</code>.
287 <emphasis><code>boolean checkDn(string $dn, array
288 &$keys, array &$vals, string|null $caseFold)</code>
293 Checks if a given DN <varname>$dn</varname> is malformed. If
294 <varname>$keys</varname> or <varname>$keys</varname> and
295 <varname>$vals</varname> are given, these arrays will be filled with the
296 appropriate DN keys and values.
302 <emphasis><code>string implodeRdn(array $part, string|null
303 $caseFold)</code> </emphasis>
307 Returns a DN part in the form
308 <code>$attribute=$value</code>
314 <emphasis><code>string implodeDn(array $dnArray,
315 string|null $caseFold, string $separator)</code>
321 Implodes an array in the form delivered by
322 <methodname>Zend_Ldap_Dn::explodeDn()</methodname> to a DN string.
323 <varname>$separator</varname> defaults to <code>','</code> but some LDAP
324 servers also understand <code>';'</code>. <varname>$dnArray</varname>
328 <programlisting language="php"><![CDATA[
330 array("cn" => "name1", "uid" => "user"),
331 array("cn" => "name2"),
332 array("dc" => "example"),
341 <emphasis><code>boolean isChildOf(string|Zend_Ldap_Dn
342 $childDn, string|Zend_Ldap_Dn $parentDn)</code> </emphasis>
346 Checks if given <varname>$childDn</varname> is beneath
347 <varname>$parentDn</varname> subtree.