cvs: peardoc /en/package/networking net-ldap.xml /en/package/networking/net-ldap attributes.xml connect.xml fetching.xml search.xml

From: Date: Tue, 26 Jun 2007 08:58:03 +0000
Subject: cvs: peardoc /en/package/networking net-ldap.xml /en/package/networking/net-ldap attributes.xml connect.xml fetching.xml search.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-9822@lists.php.net to get a copy of this message
beni Tue Jun 26 08:58:03 2007 UTC Added files: /peardoc/en/package/networking/net-ldap attributes.xml fetching.xml Modified files: /peardoc/en/package/networking net-ldap.xml /peardoc/en/package/networking/net-ldap connect.xml search.xml Log: * Added documentation to Net_LDAP

http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap.xml?r1=1.5&r2=1.6&diff_format=u Index: peardoc/en/package/networking/net-ldap.xml diff -u peardoc/en/package/networking/net-ldap.xml:1.5 peardoc/en/package/networking/net-ldap.xml:1.6 --- peardoc/en/package/networking/net-ldap.xml:1.5 Tue Jun 26 06:27:31 2007 +++ peardoc/en/package/networking/net-ldap.xml Tue Jun 26 08:58:03 2007 @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <sect1 id="package.networking.net-ldap"> <title>Net_LDAP</title> - + <para> Net_LDAP allows you to query and manipulate the data stored in directory servers using PHP in an object-oriented way. @@ -10,11 +10,13 @@ <para> Detailed usage examples are available at: <literal>/your/pear/path/docs/Net_LDAP/examples/</literal> </para> - + &package.networking.net-ldap.introduction; &package.networking.net-ldap.errorhandling; &package.networking.net-ldap.connect; &package.networking.net-ldap.search; + &package.networking.net-ldap.fetching; + &package.networking.net-ldap.attributes; </sect1> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/connect.xml?r1=1.4&r2=1.5&diff_format=u Index: peardoc/en/package/networking/net-ldap/connect.xml diff -u peardoc/en/package/networking/net-ldap/connect.xml:1.4 peardoc/en/package/networking/net-ldap/connect.xml:1.5 --- peardoc/en/package/networking/net-ldap/connect.xml:1.4 Fri Jun 22 11:28:26 2007 +++ peardoc/en/package/networking/net-ldap/connect.xml Tue Jun 26 08:58:03 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry id="package.networking.net-ldap.connecting"> <refnamediv> <refname>Configuration and connecting</refname> @@ -15,7 +15,7 @@ It takes one parameter, an array full of configuration options, and either returns a <classname>Net_LDAP</classname> object if connecting works, or a - <classname>PEAR_Error</classname> object in case of a failure. + <classname>Net_LDAP_Error</classname> object in case of a failure. </para> <para> @@ -116,7 +116,7 @@ // Connecting using the configuration: $ldap = Net_LDAP::connect($config); -// testing for connection error +// Testing for connection error if (PEAR::isError($ldap)) { die('Could not connect to LDAP-server: '.$ldap->getMessage()); } http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/search.xml?r1=1.3&r2=1.4&diff_format=u Index: peardoc/en/package/networking/net-ldap/search.xml diff -u peardoc/en/package/networking/net-ldap/search.xml:1.3 peardoc/en/package/networking/net-ldap/search.xml:1.4 --- peardoc/en/package/networking/net-ldap/search.xml:1.3 Fri Jun 22 11:28:26 2007 +++ peardoc/en/package/networking/net-ldap/search.xml Tue Jun 26 08:58:03 2007 @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <refentry id="package.networking.net-ldap.search"> <refnamediv> <refname>Search</refname> - <refpurpose>How to search entries</refpurpose> + <refpurpose>Searching entries</refpurpose> </refnamediv> <refsect1> @@ -25,7 +25,8 @@ <listitem> <para> <literal>$filter</literal> is the query filter that determines which - results are returned. It is either a string or better a <classname>Net_LDAP_Filter</classname>-object. + results are returned. It is either a string (experts use only) or better a <classname>Net_LDAP_Filter</classname>-object. + <classname>Net_LDAP_Filter</classname> automatically deals with LDAP-Filter escaping issues. </para> </listitem> @@ -107,25 +108,45 @@ </listitem> </itemizedlist> + + The <function>search</function> method will return either a <classname>Net_LDAP_Search</classname> object or a <classname>Net_LDAP_Error</classname>. + You can use the <classname>Net_LDAP_Search</classname>-object to trigger further actions + like counting how many entries where found or to retrieve the found entries. </para> <example> - <title>Making a search query</title> + <title>Making a search query and fetching results</title> <programlisting role="php"><![CDATA[ -$filter = 'sn=Joe*'; +// Building a very basic filter +// we want to find all Entries whose surnames start with "Joe": +$filter = Net_LDAP_Filter::create('sn', 'begins', 'Joe'); + +// We define a custom searchbase here. If you pass NULL, the basedn provided +// in the Net_LDAP configuration will be used. This is often not what you want. $searchbase = 'ou=addressbook,dc=example,dc=org'; + +// Some options: +// We search all subtrees beneath 'ou=addressbook,dc=example,dc=org' +// and we select the attribute 'sn'. It is a good practice to limit the +// requested attributes to only those you actually want to use later. $options = array( 'scope' => 'sub', 'attributes' => array('sn') ); -$result = $ldap->search($searchbase, $filter, $options); -if (PEAR::isError($result)) { - die($result->getMessage() . "\n"); +// Perform the search! +$search = $ldap->search($searchbase, $filter, $options); + +// Test for search errors: +if (PEAR::isError($search)) { + die($search->getMessage() . "\n"); } + +// Say how many entries we have found: +echo "Found " . $search->count() . " entries!"; + ]]></programlisting> </example> - </refsect1> </refentry> <!-- Keep this comment at the end of the file @@ -146,4 +167,4 @@ vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> +--> \ No newline at end of file http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/attributes.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-ldap/attributes.xml +++ peardoc/en/package/networking/net-ldap/attributes.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-ldap.attributes"> <refnamediv> <refname>Attributes</refname> <refpurpose>Reading/adding/changing/deleting attributes from entries</refpurpose> </refnamediv> <refsect1> <title>Reading attributes</title> <para> </para> <example> <title>Reading attributes</title> <programlisting role="php"><![CDATA[ // TODO ]]></programlisting> </example> </refsect1> <refsect1> <title>General information regarding attribute changing</title> <para> It is important to know how attribute changing works. Modifications to an entry through the <classname>Net_LDAP_Entry</classname>-object are local only. After you have made all changes and want to transfer them to the directory server, you must call <function>update</function> of the <classname>Net_LDAP_Entry</classname> object. This will return either <literal>TRUE</literal> or an <classname>Net_LDAP_Error</classname>. </para> </refsect1> <refsect1> <title>Adding attributes</title> <para> </para> <example> <title>Adding attributes</title> <programlisting role="php"><![CDATA[ // TODO ]]></programlisting> </example> </refsect1> <refsect1> <title>Changing attributes</title> <para> </para> <example> <title>Changing attributes</title> <programlisting role="php"><![CDATA[ // TODO ]]></programlisting> </example> </refsect1> <refsect1> <title>Deleting attributes</title> <para> </para> <example> <title>Deleting attributes</title> <programlisting role="php"><![CDATA[ // TODO ]]></programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/fetching.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-ldap/fetching.xml +++ peardoc/en/package/networking/net-ldap/fetching.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-ldap.fetching"> <refnamediv> <refname>Fetching entries</refname> <refpurpose>Retrieving entries directly or from a searchresult</refpurpose> </refnamediv> <refsect1> <title>Retrieving entries directly</title> <para> You can retrieve directory entries in two ways, either directly or from a performed search request. If you want to fetch an entry directly, you need to know its absolute distinguished name (DN). To directly fetch an known entry from the directory server, you use <classname>Net_LDAP</classname>'s <function>getEntry</function> method. It takes two parameters: The DN of the entry and the attributes you want to read from the entry. It returns a <classname>Net_LDAP_Entry</classname> object if fetching worked, or a <classname>Net_LDAP_Error</classname> object in case of a failure. </para> <para> You may also check if the entry exists in the server before you fetch it. This can be achieved by <classname>Net_LDAP</classname>'s <function>dnExists</function> which takes the DN to test and returns either true or false. </para> <example> <title>Fetching an entry directly</title> <programlisting role="php"><![CDATA[ // Defining the DN we want to fetch; // we want to select the given- and the surname $dn = 'cn=admin,o=example,dc=org'; $entry = $ldap->getEntry($dn, array('gn', 'sn')); // Error checking is important! if (Net_LDAP::isError($entry)) { die('Could not fetch entry: '.$entry->getMessage()); } ]]></programlisting> </example> </refsect1> <refsect1> <title>Retrieving entries from a searchresult</title> <para> The second way to retrieve entries is from a searchresult. As described in chapter "<link linkend="package.networking.net-ldap.search">Search</link>", you access the entries of a search result through the <classname>Net_LDAP_Search</classname>-object resulting from <classname>Net_LDAP</classname>'s <function>search</function> method. Each of the following methods return a <classname>Net_LDAP_Error</classname>-object if something goes wrong, so remember to test for errors! You have several ways to read the entries: <table> <title>Possible ways to fetch entries</title> <tgroup cols="2"> <thead> <row> <entry>Method of <classname>Net_LDAP_Search</classname></entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry><function>entries</function></entry> <entry>This returns the entries at once unsorted.</entry> </row> <row> <entry><function>as_struct</function></entry> <entry>This returns all entries as multidimensional array instead of <classname>Net_LDAP_Entry</classname>-objects. The array keys of the first dimension are the DNs and the value is an array containing all attributes. The array keys of the second level are the attributes names; the value of the second level is an array containing all the attributes values. Note, that even if there are no or just one value, an array is present.</entry> </row> <row> <entry><function>sorted</function></entry> <entry>Use this if you want to get the entries at once but sorted. You can sort by several attributes which can contain multiple values.</entry> </row> <row> <entry><function>sorted_as_struct</function></entry> <entry>Like <function>as_struct</function>, this returns the entries as multidimensional array, but in this case sorted.</entry> </row> <row> <entry><function>shiftEntry</function></entry> <entry>This returns one entry from the beginning of the search result. Since this returns <literal>FALSE</literal> if all entries are fetched, <function>shiftEntry</function> is perfectly appropriate to get used inside a while-loop. Take care not to mix <function>shiftEntry</function> and <function>popEntry</function>!</entry> </row> <row> <entry><function>popEntry</function></entry> <entry>Exactly the same as shiftEntry, but returns the entry from the end of the searchresult. Again, be sure to dont mix <function>shiftEntry</function> and <function>popEntry</function>!</entry> </row> </tbody> </tgroup> </table> To directly fetch an known entry from the directory server, you use <classname>Net_LDAP</classname>'s <function>getEntry</function> method. It takes two parameters: The DN of the entry and the attributes you want to read from the entry. It returns a <classname>Net_LDAP_Entry</classname> object if fetching worked, or a <classname>Net_LDAP_Error</classname> object in case of a failure. </para> <para> You may also check if the entry exists in the server before you fetch it. This can be achieved by <classname>Net_LDAP</classname>'s <function>dnExists</function> which takes the DN to test and returns either true or false. </para> <example> <title>Fetching all entries from searchresult</title> <programlisting role="php"><![CDATA[ // return all entries: $entry = $search->entries(); ]]></programlisting> </example> <example> <title>Fetching all entries from searchresult: sorted</title> <programlisting role="php"><![CDATA[ // return sorted by first 'sn' then 'gn': $entry = $search->sorted(array('sn', 'gn'))); ]]></programlisting> </example> <example> <title>Fetching entries one by one inside a while loop</title> <programlisting role="php"><![CDATA[ // return entries one by one: while ( $entry = $search->shiftEntry() ) { // do something, like printing the DN of the entry; // in a real case, dont forget to test for errors! echo "ENTRY: " . $entry->dn() . "; } ]]></programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#9822) next »