File: Zend_Ldap-Usage.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (177 lines) | stat: -rw-r--r-- 5,838 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.ldap.usage">
    <title>Usage Scenarios</title>

    <sect2 id="zend.ldap.usage.authentication">
        <title>Authentication scenarios</title>

        <sect3 id="zend.ldap.usage.authentication.openldap">
            <title>OpenLDAP</title>
            <para/>
        </sect3>

        <sect3 id="zend.ldap.usage.authentication.activedirectory">
            <title>ActiveDirectory</title>
            <para/>
        </sect3>
    </sect2>

    <sect2 id="zend.ldap.usage.basic">
        <title>Basic CRUD operations</title>

        <sect3 id="zend.ldap.usage.basic.retrieve">
            <title>Retrieving data from the LDAP</title>

            <example id="zend.ldap.usage.basic.retrieve.dn">
                <title>Getting an entry by its DN</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
/*
$hm is an array of the following structure
array(
    'dn'          => 'cn=Hugo Müller,ou=People,dc=my,dc=local',
    'cn'          => array('Hugo Müller'),
    'sn'          => array('Müller'),
    'objectclass' => array('inetOrgPerson', 'top'),
    ...
)
*/
]]></programlisting>
            </example>

            <example id="zend.ldap.usage.basic.retrieve.exists">
                <title>Check for the existence of a given DN</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$isThere = $ldap->exists('cn=Hugo Müller,ou=People,dc=my,dc=local');
]]></programlisting>
            </example>

            <example id="zend.ldap.usage.basic.retrieve.counting-children">
                <title>Count children of a given DN</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$childrenCount = $ldap->countChildren(
                            'cn=Hugo Müller,ou=People,dc=my,dc=local');
]]></programlisting>
            </example>

            <example id="zend.ldap.usage.basic.retrieve.search">
                <title>Searching the LDAP tree</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$result = $ldap->search('(objectclass=*)',
                        'ou=People,dc=my,dc=local',
                        Zend_Ldap_Ext::SEARCH_SCOPE_ONE);
foreach ($result as $item) {
    echo $item["dn"] . ': ' . $item['cn'][0] . PHP_EOL;
}
]]></programlisting>
            </example>
        </sect3>

        <sect3 id="zend.ldap.usage.basic.add">
            <title>Adding data to the LDAP</title>

            <example>
                <title>Add a new entry to the LDAP</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$entry = array();
Zend_Ldap_Attribute::setAttribute($entry, 'cn', 'Hans Meier');
Zend_Ldap_Attribute::setAttribute($entry, 'sn', 'Meier');
Zend_Ldap_Attribute::setAttribute($entry, 'objectClass', 'inetOrgPerson');
$ldap->add('cn=Hans Meier,ou=People,dc=my,dc=local', $entry);
]]></programlisting>
            </example>
        </sect3>

        <sect3 id="zend.ldap.usage.basic.delete">
            <title>Deleting from the LDAP</title>

            <example>
                <title>Delete an existing entry from the LDAP</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$ldap->delete('cn=Hans Meier,ou=People,dc=my,dc=local');
]]></programlisting>
            </example>
        </sect3>

        <sect3 id="zend.ldap.usage.basic.update">
            <title>Updating the LDAP</title>

            <example>
                <title>Update an existing entry on the LDAP</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
Zend_Ldap_Attribute::setAttribute($hm, 'mail', 'mueller@my.local');
Zend_Ldap_Attribute::setPassword($hm,
                                 'newPa$$w0rd',
                                 Zend_Ldap_Attribute::PASSWORD_HASH_SHA1);
$ldap->update('cn=Hugo Müller,ou=People,dc=my,dc=local', $hm);
]]></programlisting>
            </example>
        </sect3>
    </sect2>

    <sect2 id="zend.ldap.usage.extended">
        <title>Extended operations</title>

        <sect3 id="zend.ldap.usage.extended.copy-and-move">
            <title>Copy and move entries in the LDAP</title>

            <example id="zend.ldap.usage.extended.copy-and-move.copy">
                <title>Copy a LDAP entry recursively with all its descendants</title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$ldap->copy('cn=Hugo Müller,ou=People,dc=my,dc=local',
            'cn=Hans Meier,ou=People,dc=my,dc=local',
            true);
]]></programlisting>
            </example>

            <example id="zend.ldap.usage.extended.copy-and-move.move-to-subtree">
                <title>
                    Move a LDAP entry recursively with all its descendants to a different subtree
                </title>

                <programlisting language="php"><![CDATA[
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap->bind();
$ldap->moveToSubtree('cn=Hugo Müller,ou=People,dc=my,dc=local',
                     'ou=Dismissed,dc=my,dc=local',
                     true);
]]></programlisting>
            </example>
        </sect3>
    </sect2>
</sect1>