[GENERIC] Zend_Translate:
[zend.git] / documentation / manual / en / module_specs / Zend_Ldap-Usage.xml
blob62e0280a07dcf954917ff9831c87596d924c9f9f
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- Reviewed: no -->
3 <sect1 id="zend.ldap.usage">
4     <title>Usage Scenarios</title>
6     <sect2 id="zend.ldap.usage.authentication">
7         <title>Authentication scenarios</title>
9         <sect3 id="zend.ldap.usage.authentication.openldap">
10             <title>OpenLDAP</title>
11             <para/>
12         </sect3>
14         <sect3 id="zend.ldap.usage.authentication.activedirectory">
15             <title>ActiveDirectory</title>
16             <para/>
17         </sect3>
18     </sect2>
20     <sect2 id="zend.ldap.usage.basic">
21         <title>Basic CRUD operations</title>
23         <sect3 id="zend.ldap.usage.basic.retrieve">
24             <title>Retrieving data from the LDAP</title>
26             <example id="zend.ldap.usage.basic.retrieve.dn">
27                 <title>Getting an entry by its DN</title>
29                 <programlisting language="php"><![CDATA[
30 $options = array(/* ... */);
31 $ldap = new Zend_Ldap($options);
32 $ldap->bind();
33 $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
35 $hm is an array of the following structure
36 array(
37     'dn'          => 'cn=Hugo Müller,ou=People,dc=my,dc=local',
38     'cn'          => array('Hugo Müller'),
39     'sn'          => array('Müller'),
40     'objectclass' => array('inetOrgPerson', 'top'),
41     ...
44 ]]></programlisting>
45             </example>
47             <example id="zend.ldap.usage.basic.retrieve.exists">
48                 <title>Check for the existence of a given DN</title>
50                 <programlisting language="php"><![CDATA[
51 $options = array(/* ... */);
52 $ldap = new Zend_Ldap($options);
53 $ldap->bind();
54 $isThere = $ldap->exists('cn=Hugo Müller,ou=People,dc=my,dc=local');
55 ]]></programlisting>
56             </example>
58             <example id="zend.ldap.usage.basic.retrieve.counting-children">
59                 <title>Count children of a given DN</title>
61                 <programlisting language="php"><![CDATA[
62 $options = array(/* ... */);
63 $ldap = new Zend_Ldap($options);
64 $ldap->bind();
65 $childrenCount = $ldap->countChildren(
66                             'cn=Hugo Müller,ou=People,dc=my,dc=local');
67 ]]></programlisting>
68             </example>
70             <example id="zend.ldap.usage.basic.retrieve.search">
71                 <title>Searching the LDAP tree</title>
73                 <programlisting language="php"><![CDATA[
74 $options = array(/* ... */);
75 $ldap = new Zend_Ldap($options);
76 $ldap->bind();
77 $result = $ldap->search('(objectclass=*)',
78                         'ou=People,dc=my,dc=local',
79                         Zend_Ldap_Ext::SEARCH_SCOPE_ONE);
80 foreach ($result as $item) {
81     echo $item["dn"] . ': ' . $item['cn'][0] . PHP_EOL;
83 ]]></programlisting>
84             </example>
85         </sect3>
87         <sect3 id="zend.ldap.usage.basic.add">
88             <title>Adding data to the LDAP</title>
90             <example>
91                 <title>Add a new entry to the LDAP</title>
93                 <programlisting language="php"><![CDATA[
94 $options = array(/* ... */);
95 $ldap = new Zend_Ldap($options);
96 $ldap->bind();
97 $entry = array();
98 Zend_Ldap_Attribute::setAttribute($entry, 'cn', 'Hans Meier');
99 Zend_Ldap_Attribute::setAttribute($entry, 'sn', 'Meier');
100 Zend_Ldap_Attribute::setAttribute($entry, 'objectClass', 'inetOrgPerson');
101 $ldap->add('cn=Hans Meier,ou=People,dc=my,dc=local', $entry);
102 ]]></programlisting>
103             </example>
104         </sect3>
106         <sect3 id="zend.ldap.usage.basic.delete">
107             <title>Deleting from the LDAP</title>
109             <example>
110                 <title>Delete an existing entry from the LDAP</title>
112                 <programlisting language="php"><![CDATA[
113 $options = array(/* ... */);
114 $ldap = new Zend_Ldap($options);
115 $ldap->bind();
116 $ldap->delete('cn=Hans Meier,ou=People,dc=my,dc=local');
117 ]]></programlisting>
118             </example>
119         </sect3>
121         <sect3 id="zend.ldap.usage.basic.update">
122             <title>Updating the LDAP</title>
124             <example>
125                 <title>Update an existing entry on the LDAP</title>
127                 <programlisting language="php"><![CDATA[
128 $options = array(/* ... */);
129 $ldap = new Zend_Ldap($options);
130 $ldap->bind();
131 $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
132 Zend_Ldap_Attribute::setAttribute($hm, 'mail', 'mueller@my.local');
133 Zend_Ldap_Attribute::setPassword($hm,
134                                  'newPa$$w0rd',
135                                  Zend_Ldap_Attribute::PASSWORD_HASH_SHA1);
136 $ldap->update('cn=Hugo Müller,ou=People,dc=my,dc=local', $hm);
137 ]]></programlisting>
138             </example>
139         </sect3>
140     </sect2>
142     <sect2 id="zend.ldap.usage.extended">
143         <title>Extended operations</title>
145         <sect3 id="zend.ldap.usage.extended.copy-and-move">
146             <title>Copy and move entries in the LDAP</title>
148             <example id="zend.ldap.usage.extended.copy-and-move.copy">
149                 <title>Copy a LDAP entry recursively with all its descendants</title>
151                 <programlisting language="php"><![CDATA[
152 $options = array(/* ... */);
153 $ldap = new Zend_Ldap($options);
154 $ldap->bind();
155 $ldap->copy('cn=Hugo Müller,ou=People,dc=my,dc=local',
156             'cn=Hans Meier,ou=People,dc=my,dc=local',
157             true);
158 ]]></programlisting>
159             </example>
161             <example id="zend.ldap.usage.extended.copy-and-move.move-to-subtree">
162                 <title>
163                     Move a LDAP entry recursively with all its descendants to a different subtree
164                 </title>
166                 <programlisting language="php"><![CDATA[
167 $options = array(/* ... */);
168 $ldap = new Zend_Ldap($options);
169 $ldap->bind();
170 $ldap->moveToSubtree('cn=Hugo Müller,ou=People,dc=my,dc=local',
171                      'ou=Dismissed,dc=my,dc=local',
172                      true);
173 ]]></programlisting>
174             </example>
175         </sect3>
176     </sect2>
177 </sect1>