cvs: peardoc /en/package/networking/net-ldap connect.xml filter.xml introduction.xml search.xml
| From: | Benedikt Hallinger | Date: | Wed, 04 Jun 2008 08:51:29 +0000 |
| Subject: | cvs: peardoc /en/package/networking/net-ldap connect.xml filter.xml introduction.xml search.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-10815@lists.php.net to get a copy of this message | ||
beni Wed Jun 4 08:51:29 2008 UTC
Added files:
/peardoc/en/package/networking/net-ldap filter.xml
Modified files:
/peardoc/en/package/networking/net-ldap connect.xml
introduction.xml search.xml
Log:
* Some doc enhancements
* new filter doc
http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/connect.xml?r1=1.6&r2=1.7&diff_format=u Index: peardoc/en/package/networking/net-ldap/connect.xml diff -u peardoc/en/package/networking/net-ldap/connect.xml:1.6 peardoc/en/package/networking/net-ldap/connect.xml:1.7 --- peardoc/en/package/networking/net-ldap/connect.xml:1.6 Tue Jul 24 07:05:08 2007 +++ peardoc/en/package/networking/net-ldap/connect.xml Wed Jun 4 08:51:29 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.networking.net-ldap.connecting"> <refnamediv> <refname>Configuration and connecting</refname> @@ -84,7 +84,10 @@ <row> <entry><literal>filter</literal></entry> - <entry>Default search filter</entry> + <entry> + Default search filter (string or preferably <classname>Net_LDAP_Filter</classname> object). + See <link linkend="package.networking.net-ldap.filter">LDAP filters</link> + </entry> <entry><literal>(objectClass=*)</literal></entry> </row> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/introduction.xml?r1=1.2&r2=1.3&diff_format=u Index: peardoc/en/package/networking/net-ldap/introduction.xml diff -u peardoc/en/package/networking/net-ldap/introduction.xml:1.2 peardoc/en/package/networking/net-ldap/introduction.xml:1.3 --- peardoc/en/package/networking/net-ldap/introduction.xml:1.2 Tue Jan 15 08:38:21 2008 +++ peardoc/en/package/networking/net-ldap/introduction.xml Wed Jun 4 08:51:29 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <refentry id="package.networking.net-ldap.introduction"> <refnamediv> <refname>Introduction</refname> @@ -80,6 +80,7 @@ however this has some drawbacks (including escaping issues). For this reason, you can use the <classname>Net_LDAP_Filter</classname> class to easily build and combine your filters. + LDAP filters are extensively explained at the chapter <link linkend="package.networking.net-ldap.filter">LDAP filters</link>. </entry> </row> <row> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/search.xml?r1=1.6&r2=1.7&diff_format=u Index: peardoc/en/package/networking/net-ldap/search.xml diff -u peardoc/en/package/networking/net-ldap/search.xml:1.6 peardoc/en/package/networking/net-ldap/search.xml:1.7 --- peardoc/en/package/networking/net-ldap/search.xml:1.6 Tue Jan 8 06:55:46 2008 +++ peardoc/en/package/networking/net-ldap/search.xml Wed Jun 4 08:51:29 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.networking.net-ldap.search"> <refnamediv> <refname>Search</refname> @@ -7,8 +7,17 @@ </refnamediv> <refsect1> + <title>A short note on DNs</title> + <para> + It may be possible that restricted characters (",", "+", """, "\", "<![CDATA[<]]>", ">", ";", "#", "=", space or a hexpair) are used in attributes or values inside the DN. + You should have a look to the APIdoc of <classname>Net_LDAP2_Util::</classname><function>escape_dn_value</function>, + <classname>Net_LDAP2_Util::</classname><function>unescape_dn_value</function>, <classname>Net_LDAP2_Util::</classname><function>ldap_explode_dn</function> and <classname>Net_LDAP2_Util::</classname><function>canonical_dn</function>. + These functions can be used to safely handle DNs. + </para> + </refsect1> + + <refsect1> <title>Searching some entries</title> - <para> After connecting to the server, you can use <classname>Net_LDAP</classname>'s <function>search</function> method to search the directory. The method takes @@ -27,6 +36,7 @@ <literal>$filter</literal> is the query filter that determines which 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. + LDAP filters are extensively explained at the chapter <link linkend="package.networking.net-ldap.filter">LDAP filters</link>. </para> </listitem> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/filter.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-ldap/filter.xml +++ peardoc/en/package/networking/net-ldap/filter.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-ldap.filter"> <refnamediv> <refname>LDAP filters</refname> <refpurpose>Introduction to and usage of LDAP filters</refpurpose> </refnamediv> <refsect1> <title>What are LDAP filters?</title> <para> LDAP filters are defined in <ulink url="http://www.ietf.org/rfc/rfc2254.txt">RFC 2254</ulink> and something like the WHERE clause in SQL seelct statements - they filter the data returned from some search request - in this case the entries returned from the directory server. With Net_LDAP, you may use plain strings as filters, or preferrably, the <classname>Net_LDAP_Filter</classname> class which mostly releases you of the burden to escape yourself and to remember all the various special characters needed for constructing and combining filters. </para> <para>Where and how to use filters is described in chapter <link linkend="package.networking.net-ldap.search">Search</link>.</para> </refsect1> <refsect1> <title>Some LDIF filter basics</title> <para> Although you should preferably use the <classname>Net_LDAP_Filter</classname> class to construct your LDAP filters, some theory may be interesting and helpful in understanding how to construct LDAP filters and what they are capable of. </para> <para> Basic LDAP filters are composed of an "[attribute][operator][value]" pair enclosed by round brackets. There are several comparison operators available: "=" (equal), ">" (greater), <![CDATA["<"]]> (less), ">=" (greater or equal), <![CDATA["<="]]> (less or equal) and "=~" (phonetical similar). The exact match behavior is defined by the attribute syntax of the attribute to which the filter should apply. </para> <example> <title>Some basic string filters</title> <programlisting role="php"><![CDATA[ // Filter entries whose first name is 'Benedikt': $filter = '(givenName=Benedikt)'; // Filter entries which have an employeenumber higher or equal than 1424: $filter = '(employeeNumber>=1424)'; // Filter entries whose first name sounds similar to "Stephane" // This should also find "Stephen" and "Stefan" (depending on implementation) $filter = '(givenName=~Stephane)'; ]]></programlisting> </example> <para> The value part of the basic filter construct could also include a special character: "*". The star acts as placeholder for none, one or several characters at that position. "V*lue" would therefore match against "Value", "Vlue", "VaaAaAalue" and so on. There are some special named combinations using the star, but they work exactly the same way: <table> <title>Special named placeholder combinations</title> <tgroup cols="3"> <thead> <row> <entry>Name</entry> <entry>Value</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry>present</entry><entry>*</entry><entry>Also refered to as "any". Finds any entry containing any (unless empty) value for the named attribute.</entry></row> <row><entry>begins</entry><entry>value*</entry><entry>value starts with some fixed string</entry></row> <row><entry>ends</entry><entry>*value</entry><entry>value ends with some fixed string</entry></row> <row><entry>contains</entry><entry>*value*</entry><entry>value contains some fixed string</entry></row> </tbody> </tgroup> </table> </para> <para> Basic filters can be combined using the three logical operators <![CDATA["&"]]> (and), <![CDATA["|"]]> (or) and <![CDATA["!"]]> (not). Note, that the smallest filter component, the basic filter enclosed in round brackets, remains isolated: instead of just adding another "[attribute][operator][value]" pair into the brackets, a new bracket level is introduced that contains all filter components that should be combined. Note also, that the logical operator does stand in front of all filter components, not between them as common in programming languages. </para> <example> <title>Combining string filters</title> <programlisting role="php"><![CDATA[ // Search all 'Benedikt's with phone number 1234567890 $filter = '(&(givenName=Benedikt)(telephoneNumber=1234567890))'; // Search the same, but exclude person "Benedikt Foobar" // Note that the "not" is a logical operator and thus needs its own // surrounding bracket. This explains nicely, that each bracket level // is evaluated independently from surrounding brackets. $filter = '(&(givenName=Benedikt)(telephoneNumber=1234567890)(!(sureName=Foobar)))'; ]]></programlisting> </example> </refsect1> <refsect1> <title>The Net_LDAP_Filter class</title> <para> As you will read below, there are some special characters inside the LDAP filter definition and thus must be escaped. These are mainly the special characters used directly by the filter syntax like braces and the logical operators. Despite those, there are some other cases which need special threatment. Nearly all of this cases are hidden through the <classname>Net_LDAP_Filter</classname> class so you should only consider using string filters if you need to or you know what you are doing. If you need a filter string, you may also use <classname>Net_LDAP_Filter</classname>s <function>toString</function> function after building the filter. </para> <para> The filter class has two different usage models: one for constructing basic filters and another to combine them logically. This has to do with the syntax of LDAP filters you may read below. </para> <refsect2> <title>Creating filters</title> <para> For creating basic filter components, you need to use the <function>create</function> factory method. There, you combine three items: an attribute to filter for, a matching rule for comparison and a value that is beeing compared with the servers entries. The given value is automatically escaped, so you need take care if you want to use the star placeholder. In this case, you need to pass <literal>FALSE</literal> as fourth parameter to <function>create</function> which causes <literal>value</literal> to be threaten as-is. This of course also means, that you need to escape the parts of the value that may contain restricted characters yourself using <classname>Net_LDAP2_Util::</classname><function>escape_filter_value</function>. To learn what characters are restricted, refer to <ulink url="http://www.ietf.org/rfc/rfc2254.txt">RFC 2254</ulink> or the documentation of <classname>Net_LDAP2_Util::</classname><function>escape_filter_value</function>; otherwise its safe to always escape. </para> <para> The matching rules partly follow the basic filter matching rules described above, but are enhanced to make your life easier: <table> <title>create()s matching rules</title> <tgroup cols="2"> <thead> <row> <entry>Rule</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry>equals</entry><entry>One of <literal>attribute</literal>s values is exactly <literal>value</literal>. Please note that case sensitiviness depends on the matching rule defined in the attributes schema syntax.</entry></row> <row><entry>begins</entry><entry>One of <literal>attribute</literal>s values must begin with <literal>value</literal></entry></row> <row><entry>ends</entry><entry>One of <literal>attribute</literal>s values must end with <literal>value</literal></entry></row> <row><entry>contains</entry><entry>One of <literal>attribute</literal>s values must contain <literal>value</literal></entry></row> <row><entry>present | any</entry><entry>The <literal>attribute</literal> can contain any value but must be existent</entry></row> <row><entry>greater</entry><entry>The <literal>attribute</literal>s value is greater than <literal>value</literal></entry></row> <row><entry>less</entry><entry>The <literal>attribute</literal>s value is less than <literal>value</literal></entry></row> <row><entry>greaterOrEqual</entry><entry>The <literal>attribute</literal>s value is greater or equal than <literal>value</literal></entry></row> <row><entry>lessOrEqual</entry><entry>The <literal>attribute</literal>s value is less or equal than <literal>value</literal></entry></row> <row><entry>approx</entry><entry>One of <literal>attribute</literal>s values sounds similar to <literal>value</literal>. The matching behavior depends on the server implementation.</entry></row> </tbody> </tgroup> </table> </para> <example> <title>Creating LDAP filters</title> <programlisting role="php"><![CDATA[ // Filter entries whose first name is 'Benedikt': $filter = Net_LDAP_Filter::create('givenName', 'equals', 'Benedikt'); // Filter entries whose first name starts with 'Steph': $filter = Net_LDAP_Filter::create('givenName', 'begins', 'Steph'); // Filter entries containing 'Lone*'; matching the star character. // The automatic escaping of $value will conveniently escape the star for us. $filter = Net_LDAP_Filter::create('givenName', 'contains', 'Lone*'); // Filter entries containing 'Foo[something]Bar'; not matching the star character. // For this to work, we need to disable automatic escaping of $value by passing // false as fourth parameter. This however implies, that we take care of // proper escaping, which is showed in the example. $escaped_values = Net_LDAP2_Util::escape_filter_value(array('Foo', 'Bar')); $foo =& $escaped_values[0]; $bar =& $escaped_values[1]; $filter = Net_LDAP_Filter::create('givenName', 'contains', "$foo*$bar", false); // Filter entries whose first name sounds similar to "Stephane" // This should also find "Stephen" and "Stefan" (depending on implementation) $filter = '(givenName=~Stephane)'; ]]></programlisting> </example> </refsect2> <refsect2> <title>Combining filters</title> <para> Although the filters can be used stand alone, they can be combined to match sophisticated search requiremets. This is done by using the <function>combine</function> to combine several present <classname>Net_LDAP_Filter</classname> objects using a logical operator. The execption is the <literal>not</literal> operator since it only allows one filter object to be negated. <table> <title>combine()s operators</title> <tgroup cols="2"> <thead> <row> <entry>Rule</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry>and</entry><entry>All filter components must evaluate to <literal>true</literal> for the combined filter to be <literal>true</literal></entry></row> <row><entry>or</entry><entry>At least one filter component must evaluate to <literal>true</literal> for the combined filter to be <literal>true</literal></entry></row> <row><entry>not</entry><entry>The result of the filter component is inversed (<literal>true</literal> becomes <literal>false</literal> and vice versa). Note that this operator only accepts one filter object.</entry></row> </tbody> </tgroup> </table> <example> <title>Combining LDAP filters</title> <programlisting role="php"><![CDATA[ // Create some test filters $filter_benedikt = Net_LDAP_Filter::create('givenName', 'equals', 'Benedikt'); $filter_steph = Net_LDAP_Filter::create('givenName', 'begins', 'Steph'); $filter_foobar = Net_LDAP_Filter::create('sureName', 'equals', 'Foobar'); $filter_height = Net_LDAP_Filter::create('personHeight', 'greater', '175'); // Negate 'foobar' filter. // This filters every entry whose sure name is not 'Foobar' $filter_not_foobar = Net_LDAP_Filter::combine('not', $filter_foobar); // Build a 'and' combination to be able to search for people whose // first names start with 'Steph' and who are are taller than 175 // except those whose surname is 'Foobar' $filter_stephs_tall = Net_LDAP_Filter::combine('and', array($filter_steph, $filter_height, $filter_not_foobar)); // In any case, add every person whose first name is // 'Benedikt' to the search result. $filter_add_benedikt = Net_LDAP_Filter::combine('or', array($filter_benedikt, $filter_stephs_tall)); ]]></programlisting> </example> </para> </refsect2> <refsect2> <title>Advanced features</title> <para> You may need some advanced functionality if you have to deal with string representation of filters. <table> <title>Advanced methods</title> <tgroup cols="2"> <thead> <row> <entry>Method</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry><function>parse</function></entry><entry>Takes an filter string and parses it into a <classname>Net_LDAP_Filter</classname> object. It also verifies, that the filter syntax is correct.</entry></row> <row><entry><function>printMe</function></entry><entry>In PERLs interface, this method is called "print" but due to language constraints, we cannot use that name. Prints the string representation of this filter object to standard output or to an optional filehandle passed as parameter.</entry></row> <row><entry><function>toString</function></entry><entry>Returns the string representation of the filter object.</entry></row> </tbody> </tgroup> </table> </para> </refsect2> </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/connect.xml?r1=1.6&r2=1.7&diff_format=u Index: peardoc/en/package/networking/net-ldap/connect.xml diff -u peardoc/en/package/networking/net-ldap/connect.xml:1.6 peardoc/en/package/networking/net-ldap/connect.xml:1.7 --- peardoc/en/package/networking/net-ldap/connect.xml:1.6 Tue Jul 24 07:05:08 2007 +++ peardoc/en/package/networking/net-ldap/connect.xml Wed Jun 4 08:51:29 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.networking.net-ldap.connecting"> <refnamediv> <refname>Configuration and connecting</refname> @@ -84,7 +84,10 @@ <row> <entry><literal>filter</literal></entry> - <entry>Default search filter</entry> + <entry> + Default search filter (string or preferably <classname>Net_LDAP_Filter</classname> object). + See <link linkend="package.networking.net-ldap.filter">LDAP filters</link> + </entry> <entry><literal>(objectClass=*)</literal></entry> </row> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/introduction.xml?r1=1.2&r2=1.3&diff_format=u Index: peardoc/en/package/networking/net-ldap/introduction.xml diff -u peardoc/en/package/networking/net-ldap/introduction.xml:1.2 peardoc/en/package/networking/net-ldap/introduction.xml:1.3 --- peardoc/en/package/networking/net-ldap/introduction.xml:1.2 Tue Jan 15 08:38:21 2008 +++ peardoc/en/package/networking/net-ldap/introduction.xml Wed Jun 4 08:51:29 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <refentry id="package.networking.net-ldap.introduction"> <refnamediv> <refname>Introduction</refname> @@ -80,6 +80,7 @@ however this has some drawbacks (including escaping issues). For this reason, you can use the <classname>Net_LDAP_Filter</classname> class to easily build and combine your filters. + LDAP filters are extensively explained at the chapter <link linkend="package.networking.net-ldap.filter">LDAP filters</link>. </entry> </row> <row> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/search.xml?r1=1.6&r2=1.7&diff_format=u Index: peardoc/en/package/networking/net-ldap/search.xml diff -u peardoc/en/package/networking/net-ldap/search.xml:1.6 peardoc/en/package/networking/net-ldap/search.xml:1.7 --- peardoc/en/package/networking/net-ldap/search.xml:1.6 Tue Jan 8 06:55:46 2008 +++ peardoc/en/package/networking/net-ldap/search.xml Wed Jun 4 08:51:29 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.networking.net-ldap.search"> <refnamediv> <refname>Search</refname> @@ -7,8 +7,17 @@ </refnamediv> <refsect1> + <title>A short note on DNs</title> + <para> + It may be possible that restricted characters (",", "+", """, "\", "<![CDATA[<]]>", ">", ";", "#", "=", space or a hexpair) are used in attributes or values inside the DN. + You should have a look to the APIdoc of <classname>Net_LDAP2_Util::</classname><function>escape_dn_value</function>, + <classname>Net_LDAP2_Util::</classname><function>unescape_dn_value</function>, <classname>Net_LDAP2_Util::</classname><function>ldap_explode_dn</function> and <classname>Net_LDAP2_Util::</classname><function>canonical_dn</function>. + These functions can be used to safely handle DNs. + </para> + </refsect1> + + <refsect1> <title>Searching some entries</title> - <para> After connecting to the server, you can use <classname>Net_LDAP</classname>'s <function>search</function> method to search the directory. The method takes @@ -27,6 +36,7 @@ <literal>$filter</literal> is the query filter that determines which 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. + LDAP filters are extensively explained at the chapter <link linkend="package.networking.net-ldap.filter">LDAP filters</link>. </para> </listitem> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/filter.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-ldap/filter.xml +++ peardoc/en/package/networking/net-ldap/filter.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-ldap.filter"> <refnamediv> <refname>LDAP filters</refname> <refpurpose>Introduction to and usage of LDAP filters</refpurpose> </refnamediv> <refsect1> <title>What are LDAP filters?</title> <para> LDAP filters are defined in <ulink url="http://www.ietf.org/rfc/rfc2254.txt">RFC 2254</ulink> and something like the WHERE clause in SQL seelct statements - they filter the data returned from some search request - in this case the entries returned from the directory server. With Net_LDAP, you may use plain strings as filters, or preferrably, the <classname>Net_LDAP_Filter</classname> class which mostly releases you of the burden to escape yourself and to remember all the various special characters needed for constructing and combining filters. </para> <para>Where and how to use filters is described in chapter <link linkend="package.networking.net-ldap.search">Search</link>.</para> </refsect1> <refsect1> <title>Some LDIF filter basics</title> <para> Although you should preferably use the <classname>Net_LDAP_Filter</classname> class to construct your LDAP filters, some theory may be interesting and helpful in understanding how to construct LDAP filters and what they are capable of. </para> <para> Basic LDAP filters are composed of an "[attribute][operator][value]" pair enclosed by round brackets. There are several comparison operators available: "=" (equal), ">" (greater), <![CDATA["<"]]> (less), ">=" (greater or equal), <![CDATA["<="]]> (less or equal) and "=~" (phonetical similar). The exact match behavior is defined by the attribute syntax of the attribute to which the filter should apply. </para> <example> <title>Some basic string filters</title> <programlisting role="php"><![CDATA[ // Filter entries whose first name is 'Benedikt': $filter = '(givenName=Benedikt)'; // Filter entries which have an employeenumber higher or equal than 1424: $filter = '(employeeNumber>=1424)'; // Filter entries whose first name sounds similar to "Stephane" // This should also find "Stephen" and "Stefan" (depending on implementation) $filter = '(givenName=~Stephane)'; ]]></programlisting> </example> <para> The value part of the basic filter construct could also include a special character: "*". The star acts as placeholder for none, one or several characters at that position. "V*lue" would therefore match against "Value", "Vlue", "VaaAaAalue" and so on. There are some special named combinations using the star, but they work exactly the same way: <table> <title>Special named placeholder combinations</title> <tgroup cols="3"> <thead> <row> <entry>Name</entry> <entry>Value</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry>present</entry><entry>*</entry><entry>Also refered to as "any". Finds any entry containing any (unless empty) value for the named attribute.</entry></row> <row><entry>begins</entry><entry>value*</entry><entry>value starts with some fixed string</entry></row> <row><entry>ends</entry><entry>*value</entry><entry>value ends with some fixed string</entry></row> <row><entry>contains</entry><entry>*value*</entry><entry>value contains some fixed string</entry></row> </tbody> </tgroup> </table> </para> <para> Basic filters can be combined using the three logical operators <![CDATA["&"]]> (and), <![CDATA["|"]]> (or) and <![CDATA["!"]]> (not). Note, that the smallest filter component, the basic filter enclosed in round brackets, remains isolated: instead of just adding another "[attribute][operator][value]" pair into the brackets, a new bracket level is introduced that contains all filter components that should be combined. Note also, that the logical operator does stand in front of all filter components, not between them as common in programming languages. </para> <example> <title>Combining string filters</title> <programlisting role="php"><![CDATA[ // Search all 'Benedikt's with phone number 1234567890 $filter = '(&(givenName=Benedikt)(telephoneNumber=1234567890))'; // Search the same, but exclude person "Benedikt Foobar" // Note that the "not" is a logical operator and thus needs its own // surrounding bracket. This explains nicely, that each bracket level // is evaluated independently from surrounding brackets. $filter = '(&(givenName=Benedikt)(telephoneNumber=1234567890)(!(sureName=Foobar)))'; ]]></programlisting> </example> </refsect1> <refsect1> <title>The Net_LDAP_Filter class</title> <para> As you will read below, there are some special characters inside the LDAP filter definition and thus must be escaped. These are mainly the special characters used directly by the filter syntax like braces and the logical operators. Despite those, there are some other cases which need special threatment. Nearly all of this cases are hidden through the <classname>Net_LDAP_Filter</classname> class so you should only consider using string filters if you need to or you know what you are doing. If you need a filter string, you may also use <classname>Net_LDAP_Filter</classname>s <function>toString</function> function after building the filter. </para> <para> The filter class has two different usage models: one for constructing basic filters and another to combine them logically. This has to do with the syntax of LDAP filters you may read below. </para> <refsect2> <title>Creating filters</title> <para> For creating basic filter components, you need to use the <function>create</function> factory method. There, you combine three items: an attribute to filter for, a matching rule for comparison and a value that is beeing compared with the servers entries. The given value is automatically escaped, so you need take care if you want to use the star placeholder. In this case, you need to pass <literal>FALSE</literal> as fourth parameter to <function>create</function> which causes <literal>value</literal> to be threaten as-is. This of course also means, that you need to escape the parts of the value that may contain restricted characters yourself using <classname>Net_LDAP2_Util::</classname><function>escape_filter_value</function>. To learn what characters are restricted, refer to <ulink url="http://www.ietf.org/rfc/rfc2254.txt">RFC 2254</ulink> or the documentation of <classname>Net_LDAP2_Util::</classname><function>escape_filter_value</function>; otherwise its safe to always escape. </para> <para> The matching rules partly follow the basic filter matching rules described above, but are enhanced to make your life easier: <table> <title>create()s matching rules</title> <tgroup cols="2"> <thead> <row> <entry>Rule</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry>equals</entry><entry>One of <literal>attribute</literal>s values is exactly <literal>value</literal>. Please note that case sensitiviness depends on the matching rule defined in the attributes schema syntax.</entry></row> <row><entry>begins</entry><entry>One of <literal>attribute</literal>s values must begin with <literal>value</literal></entry></row> <row><entry>ends</entry><entry>One of <literal>attribute</literal>s values must end with <literal>value</literal></entry></row> <row><entry>contains</entry><entry>One of <literal>attribute</literal>s values must contain <literal>value</literal></entry></row> <row><entry>present | any</entry><entry>The <literal>attribute</literal> can contain any value but must be existent</entry></row> <row><entry>greater</entry><entry>The <literal>attribute</literal>s value is greater than <literal>value</literal></entry></row> <row><entry>less</entry><entry>The <literal>attribute</literal>s value is less than <literal>value</literal></entry></row> <row><entry>greaterOrEqual</entry><entry>The <literal>attribute</literal>s value is greater or equal than <literal>value</literal></entry></row> <row><entry>lessOrEqual</entry><entry>The <literal>attribute</literal>s value is less or equal than <literal>value</literal></entry></row> <row><entry>approx</entry><entry>One of <literal>attribute</literal>s values sounds similar to <literal>value</literal>. The matching behavior depends on the server implementation.</entry></row> </tbody> </tgroup> </table> </para> <example> <title>Creating LDAP filters</title> <programlisting role="php"><![CDATA[ // Filter entries whose first name is 'Benedikt': $filter = Net_LDAP_Filter::create('givenName', 'equals', 'Benedikt'); // Filter entries whose first name starts with 'Steph': $filter = Net_LDAP_Filter::create('givenName', 'begins', 'Steph'); // Filter entries containing 'Lone*'; matching the star character. // The automatic escaping of $value will conveniently escape the star for us. $filter = Net_LDAP_Filter::create('givenName', 'contains', 'Lone*'); // Filter entries containing 'Foo[something]Bar'; not matching the star character. // For this to work, we need to disable automatic escaping of $value by passing // false as fourth parameter. This however implies, that we take care of // proper escaping, which is showed in the example. $escaped_values = Net_LDAP2_Util::escape_filter_value(array('Foo', 'Bar')); $foo =& $escaped_values[0]; $bar =& $escaped_values[1]; $filter = Net_LDAP_Filter::create('givenName', 'contains', "$foo*$bar", false); // Filter entries whose first name sounds similar to "Stephane" // This should also find "Stephen" and "Stefan" (depending on implementation) $filter = '(givenName=~Stephane)'; ]]></programlisting> </example> </refsect2> <refsect2> <title>Combining filters</title> <para> Although the filters can be used stand alone, they can be combined to match sophisticated search requiremets. This is done by using the <function>combine</function> to combine several present <classname>Net_LDAP_Filter</classname> objects using a logical operator. The execption is the <literal>not</literal> operator since it only allows one filter object to be negated. <table> <title>combine()s operators</title> <tgroup cols="2"> <thead> <row> <entry>Rule</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry>and</entry><entry>All filter components must evaluate to <literal>true</literal> for the combined filter to be <literal>true</literal></entry></row> <row><entry>or</entry><entry>At least one filter component must evaluate to <literal>true</literal> for the combined filter to be <literal>true</literal></entry></row> <row><entry>not</entry><entry>The result of the filter component is inversed (<literal>true</literal> becomes <literal>false</literal> and vice versa). Note that this operator only accepts one filter object.</entry></row> </tbody> </tgroup> </table> <example> <title>Combining LDAP filters</title> <programlisting role="php"><![CDATA[ // Create some test filters $filter_benedikt = Net_LDAP_Filter::create('givenName', 'equals', 'Benedikt'); $filter_steph = Net_LDAP_Filter::create('givenName', 'begins', 'Steph'); $filter_foobar = Net_LDAP_Filter::create('sureName', 'equals', 'Foobar'); $filter_height = Net_LDAP_Filter::create('personHeight', 'greater', '175'); // Negate 'foobar' filter. // This filters every entry whose sure name is not 'Foobar' $filter_not_foobar = Net_LDAP_Filter::combine('not', $filter_foobar); // Build a 'and' combination to be able to search for people whose // first names start with 'Steph' and who are are taller than 175 // except those whose surname is 'Foobar' $filter_stephs_tall = Net_LDAP_Filter::combine('and', array($filter_steph, $filter_height, $filter_not_foobar)); // In any case, add every person whose first name is // 'Benedikt' to the search result. $filter_add_benedikt = Net_LDAP_Filter::combine('or', array($filter_benedikt, $filter_stephs_tall)); ]]></programlisting> </example> </para> </refsect2> <refsect2> <title>Advanced features</title> <para> You may need some advanced functionality if you have to deal with string representation of filters. <table> <title>Advanced methods</title> <tgroup cols="2"> <thead> <row> <entry>Method</entry> <entry>Description</entry> </row> </thead> <tbody> <row><entry><function>parse</function></entry><entry>Takes an filter string and parses it into a <classname>Net_LDAP_Filter</classname> object. It also verifies, that the filter syntax is correct.</entry></row> <row><entry><function>printMe</function></entry><entry>In PERLs interface, this method is called "print" but due to language constraints, we cannot use that name. Prints the string representation of this filter object to standard output or to an optional filehandle passed as parameter.</entry></row> <row><entry><function>toString</function></entry><entry>Returns the string representation of the filter object.</entry></row> </tbody> </tgroup> </table> </para> </refsect2> </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 -->