Zend_Ldap-Usage.xml 5.7 KB

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