Zend_Ldap-Usage.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 role="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 role="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 role="php"><![CDATA[
  51. $options = array(/* ... */);
  52. $ldap = new Zend_Ldap($options);
  53. $ldap->bind();
  54. $childrenCount = $ldap->countChildren('cn=Hugo Müller,ou=People,dc=my,dc=local');
  55. ]]></programlisting>
  56. </example>
  57. <example id="zend.ldap.usage.basic.retrieve.search">
  58. <title>Searching the LDAP tree</title>
  59. <programlisting role="php"><![CDATA[
  60. $options = array(/* ... */);
  61. $ldap = new Zend_Ldap($options);
  62. $ldap->bind();
  63. $result = $ldap->search('(objectclass=*)', 'ou=People,dc=my,dc=local', Zend_Ldap_Ext::SEARCH_SCOPE_ONE);
  64. foreach ($result as $item) {
  65. echo $item["dn"] . ': ' . $item['cn'][0] . PHP_EOL;
  66. }
  67. ]]></programlisting>
  68. </example>
  69. </sect3>
  70. <sect3 id="zend.ldap.usage.basic.add">
  71. <title>Adding data to the LDAP</title>
  72. <example>
  73. <title>Add a new entry to the LDAP</title>
  74. <programlisting role="php"><![CDATA[
  75. $options = array(/* ... */);
  76. $ldap = new Zend_Ldap($options);
  77. $ldap->bind();
  78. $entry = array();
  79. Zend_Ldap_Attribute::setAttribute($entry, 'cn', 'Hans Meier');
  80. Zend_Ldap_Attribute::setAttribute($entry, 'sn', 'Meier');
  81. Zend_Ldap_Attribute::setAttribute($entry, 'objectClass', 'inetOrgPerson');
  82. $ldap->add('cn=Hans Meier,ou=People,dc=my,dc=local', $entry);
  83. ]]></programlisting>
  84. </example>
  85. </sect3>
  86. <sect3 id="zend.ldap.usage.basic.delete">
  87. <title>Deleting from the LDAP</title>
  88. <example>
  89. <title>Delete an existing entry from the LDAP</title>
  90. <programlisting role="php"><![CDATA[
  91. $options = array(/* ... */);
  92. $ldap = new Zend_Ldap($options);
  93. $ldap->bind();
  94. $ldap->delete('cn=Hans Meier,ou=People,dc=my,dc=local');
  95. ]]></programlisting>
  96. </example>
  97. </sect3>
  98. <sect3 id="zend.ldap.usage.basic.update">
  99. <title>Updating the LDAP</title>
  100. <example>
  101. <title>Update an existing entry on the LDAP</title>
  102. <programlisting role="php"><![CDATA[
  103. $options = array(/* ... */);
  104. $ldap = new Zend_Ldap($options);
  105. $ldap->bind();
  106. $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
  107. Zend_Ldap_Attribute::setAttribute($hm, 'mail', 'mueller@my.local');
  108. Zend_Ldap_Attribute::setPassword($hm, 'newPa$$w0rd', Zend_Ldap_Attribute::PASSWORD_HASH_SHA1);
  109. $ldap->update('cn=Hugo Müller,ou=People,dc=my,dc=local', $hm);
  110. ]]></programlisting>
  111. </example>
  112. </sect3>
  113. </sect2>
  114. <sect2 id="zend.ldap.usage.extended">
  115. <title>Extended operations</title>
  116. <sect3 id="zend.ldap.usage.extended.copy-and-move">
  117. <title>Copy and move entries in the LDAP</title>
  118. <example id="zend.ldap.usage.extended.copy-and-move.copy">
  119. <title>Copy a LDAP entry recursively with all its descendants.</title>
  120. <programlisting role="php"><![CDATA[
  121. $options = array(/* ... */);
  122. $ldap = new Zend_Ldap($options);
  123. $ldap->bind();
  124. $ldap->copy('cn=Hugo Müller,ou=People,dc=my,dc=local', 'cn=Hans Meier,ou=People,dc=my,dc=local', true);
  125. ]]></programlisting>
  126. </example>
  127. <example id="zend.ldap.usage.extended.copy-and-move.move-to-subtree">
  128. <title>Move a LDAP entry recursively with all its descendants to a different subtree.</title>
  129. <programlisting role="php"><![CDATA[
  130. $options = array(/* ... */);
  131. $ldap = new Zend_Ldap($options);
  132. $ldap->bind();
  133. $ldap->moveToSubtree('cn=Hugo Müller,ou=People,dc=my,dc=local', 'ou=Dismissed,dc=my,dc=local', true);
  134. ]]></programlisting>
  135. </example>
  136. </sect3>
  137. </sect2>
  138. </sect1>