cvs: peardoc /en/package/networking/net-ldap attributes.xml fetching.xml
| From: | Benedikt Hallinger | Date: | Tue, 26 Jun 2007 14:07:02 +0000 |
| Subject: | cvs: peardoc /en/package/networking/net-ldap attributes.xml fetching.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-9824@lists.php.net to get a copy of this message | ||
beni Tue Jun 26 14:07:02 2007 UTC
Modified files:
/peardoc/en/package/networking/net-ldap attributes.xml fetching.xml
Log:
* Additions
http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/attributes.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/networking/net-ldap/attributes.xml diff -u peardoc/en/package/networking/net-ldap/attributes.xml:1.1 peardoc/en/package/networking/net-ldap/attributes.xml:1.2 --- peardoc/en/package/networking/net-ldap/attributes.xml:1.1 Tue Jun 26 08:58:03 2007 +++ peardoc/en/package/networking/net-ldap/attributes.xml Tue Jun 26 14:07:01 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.networking.net-ldap.attributes"> <refnamediv> <refname>Attributes</refname> @@ -10,16 +10,83 @@ <title>Reading attributes</title> <para> - </para> + Reading attribute values depends on the selection of those attributes at search time. + You can read attribute values using either <classname>Net_LDAP_Entry</classname>'s <function>getValues</function> or <function>getValue</function> method. + <function>getValue</function> will return an array where the keys are the attributes names. + If you use <function>getValues</function> you may pass an option: + <itemizedlist> + <listitem> + <para> + <literal>'single'</literal>: only the first value is returned as string + </para> + </listitem> + <listitem> + <para> + <literal>'all'</literal>: all values including the value count are returned in an array + </para> + </listitem> + <listitem> + <para> + <literal>'default'</literal>: in all other cases an attribute value with a single value is + returned as string, if it has multiple values it is returned + as an array (without value count) + </para> + </listitem> + </itemizedlist> + </para> <example> <title>Reading attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// read Surename, singlevalued +$surename = $entry->getValue('sn', 'single'); + +// read mail adress which may be multivalued +$mail = $entry->getValue('mail', 'all'); ]]></programlisting> </example> + + <para> + If you want to read the distinguished name of an Entry (DN), you must use a different method: <function>dn</function> + <example> + <title>Reading an entries DN</title> + <programlisting role="php"><![CDATA[ +$dn = $entry->dn(); +]]></programlisting> + </example> + </para> + </refsect1> + <refsect1> + <title>Regular expressions on attributes</title> + + <para> + PEAR::Net_LDAP features the unique feature to apply a regular expression match directly against attributes, so + you do not need to manually fetch all values and run the regex against them. + Instead, you can use <classname>Net_LDAP_Entry</classname>'s <function>preg_match</function> function. + The behavior of this function is the same as PHPs preg_match(), but the $matches array is slightly different. + It features one dimension more, since it may match for several attribute values if the attribute is multivalued. + If you pass $matches, be sure to do it via REFERENCE, because otherwise $matches remains empty. + <function>preg_match</function> returns true or false, depending on match. + </para> + <example> + <title>Performing preg_match on attribute values</title> + <programlisting role="php"><![CDATA[ +// Look, if the user has an emailadress for 'example', if so, +// we want to display the tld: +// (be sure to pass $matches as reference!) +$matches = array(); +if ( $entry->preg_match('mail', '/example\.(.+)/', &$matches) ) { + // print every TLD found for 'example': + foreach ($matches as $match) { + echo $match[1]; + } +} +]]></programlisting> + </example> + + </refsect1> <refsect1> <title>General information regarding attribute changing</title> @@ -30,18 +97,38 @@ 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>. + Another good information is, that you must select attributes at search time + if you want to add/change/delete attribute values. Otherwise Net_LDAP will most likely fail + silently giving you the wrong assumtion that everything was okay - Net_LDAP needs knowledge + of the attributes it should work with! </para> + <para>Modification of attributes is also possible through <classname>Net_LDAP</classname>'s <function>modify</function> method. + This method will call the methods described here on the <classname>Net_LDAP_Entry</classname> object given, and + directly calls an <function>update</function> after that, thus performing the changes directly on the server. + The parameter is an complex array describing the changes to be performed. It is considered for more advanced users, + because it is more compact, so please refer to the latest API documentation for more information.</para> </refsect1> <refsect1> <title>Adding attributes</title> <para> + Adding attrbiute values to an entry is an easy task. You just need to call <function>add</function>! + The parameter is an array whose keys are the attribute names and values the attributes values. + If only one attribute value should be added, the second level may be a string. + If the attribute doesn't exist so far, it will be added, if it exists, the attributes values will be added. </para> <example> <title>Adding attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// Adding several attributes: +$result = $entry->add( + array( + 'sn' => 'Doe', + 'gn' => array('John'), + 'mail' => array('john@doe.org', 'j.doe@example.org') + ) +); ]]></programlisting> </example> @@ -51,11 +138,26 @@ <title>Changing attributes</title> <para> + Changing values is with the <function>replace</function> method as easy as adding values. However, you have to be a little more careful. + The expected parameter is an array describing the new absolute state of the named + attributes. This means, if you specify a <literal>NULL</literal> value for an attribute, + this attribute will get deleted! + You may specify single values as string too. + The keys of the array are expected to be the attributes names. </para> <example> <title>Changing attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// Changing several attributes: +// 'sn' is changed to "Smith", 'gn' gets deleted and mail will +// be changed to te two new adresses +$result = $entry->replace( + array( + 'sn' => 'Smith', + 'gn' => null, + 'mail' => array('smith@example.org', 'smith@example.de') + ) +); ]]></programlisting> </example> @@ -65,11 +167,32 @@ <title>Deleting attributes</title> <para> + Using the <function>delete</function> method you are able to delete specific attributes values as well + as delete a whole attribute. + You need to specify the attribute names as array keys, the array values are the values you want to delete. + If you want to delete whiole attributes, specify them as single level array. + Special care must be taken not to delete the whole entry which will be the case if the parameter array is + omitted or set to <literal>NULL</literal>! + Also, don't mix syntax modes. If you want to delete whole attributes you can't delete specific values from another attribute + in the same function call. </para> <example> <title>Deleting attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// Delete the whole entry: +$result = $entry->delete(); + +// Delete the whole telephone number attribute: +$result = $entry->delete('telephoneNumber'); + +// Delete one specific mail attributes value: +$result = $entry->delete( array('mail' => 'j.doe@example.org') ); + +// Delete mail and telephone attributes as a whole: +$result = $entry->delete( array('mail', 'telephoneNumber') ); + +// Delete two specific mail adresses: +$result = $entry->delete( array('mail' => array('smith@example.org', 'smith@example.de')) ); ]]></programlisting> </example> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/fetching.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/networking/net-ldap/fetching.xml diff -u peardoc/en/package/networking/net-ldap/fetching.xml:1.1 peardoc/en/package/networking/net-ldap/fetching.xml:1.2 --- peardoc/en/package/networking/net-ldap/fetching.xml:1.1 Tue Jun 26 08:58:03 2007 +++ peardoc/en/package/networking/net-ldap/fetching.xml Tue Jun 26 14:07:01 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.networking.net-ldap.fetching"> <refnamediv> <refname>Fetching entries</refname> @@ -80,7 +80,8 @@ <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> + <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. + You can of course sort ascending (default) or descending - just pass the PHP constant <literal>SORT_ASC</literal> or <literal>SORT_DESC</literal> as second parameter.</entry> </row> <row>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/attributes.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/networking/net-ldap/attributes.xml diff -u peardoc/en/package/networking/net-ldap/attributes.xml:1.1 peardoc/en/package/networking/net-ldap/attributes.xml:1.2 --- peardoc/en/package/networking/net-ldap/attributes.xml:1.1 Tue Jun 26 08:58:03 2007 +++ peardoc/en/package/networking/net-ldap/attributes.xml Tue Jun 26 14:07:01 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.networking.net-ldap.attributes"> <refnamediv> <refname>Attributes</refname> @@ -10,16 +10,83 @@ <title>Reading attributes</title> <para> - </para> + Reading attribute values depends on the selection of those attributes at search time. + You can read attribute values using either <classname>Net_LDAP_Entry</classname>'s <function>getValues</function> or <function>getValue</function> method. + <function>getValue</function> will return an array where the keys are the attributes names. + If you use <function>getValues</function> you may pass an option: + <itemizedlist> + <listitem> + <para> + <literal>'single'</literal>: only the first value is returned as string + </para> + </listitem> + <listitem> + <para> + <literal>'all'</literal>: all values including the value count are returned in an array + </para> + </listitem> + <listitem> + <para> + <literal>'default'</literal>: in all other cases an attribute value with a single value is + returned as string, if it has multiple values it is returned + as an array (without value count) + </para> + </listitem> + </itemizedlist> + </para> <example> <title>Reading attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// read Surename, singlevalued +$surename = $entry->getValue('sn', 'single'); + +// read mail adress which may be multivalued +$mail = $entry->getValue('mail', 'all'); ]]></programlisting> </example> + + <para> + If you want to read the distinguished name of an Entry (DN), you must use a different method: <function>dn</function> + <example> + <title>Reading an entries DN</title> + <programlisting role="php"><![CDATA[ +$dn = $entry->dn(); +]]></programlisting> + </example> + </para> + </refsect1> + <refsect1> + <title>Regular expressions on attributes</title> + + <para> + PEAR::Net_LDAP features the unique feature to apply a regular expression match directly against attributes, so + you do not need to manually fetch all values and run the regex against them. + Instead, you can use <classname>Net_LDAP_Entry</classname>'s <function>preg_match</function> function. + The behavior of this function is the same as PHPs preg_match(), but the $matches array is slightly different. + It features one dimension more, since it may match for several attribute values if the attribute is multivalued. + If you pass $matches, be sure to do it via REFERENCE, because otherwise $matches remains empty. + <function>preg_match</function> returns true or false, depending on match. + </para> + <example> + <title>Performing preg_match on attribute values</title> + <programlisting role="php"><![CDATA[ +// Look, if the user has an emailadress for 'example', if so, +// we want to display the tld: +// (be sure to pass $matches as reference!) +$matches = array(); +if ( $entry->preg_match('mail', '/example\.(.+)/', &$matches) ) { + // print every TLD found for 'example': + foreach ($matches as $match) { + echo $match[1]; + } +} +]]></programlisting> + </example> + + </refsect1> <refsect1> <title>General information regarding attribute changing</title> @@ -30,18 +97,38 @@ 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>. + Another good information is, that you must select attributes at search time + if you want to add/change/delete attribute values. Otherwise Net_LDAP will most likely fail + silently giving you the wrong assumtion that everything was okay - Net_LDAP needs knowledge + of the attributes it should work with! </para> + <para>Modification of attributes is also possible through <classname>Net_LDAP</classname>'s <function>modify</function> method. + This method will call the methods described here on the <classname>Net_LDAP_Entry</classname> object given, and + directly calls an <function>update</function> after that, thus performing the changes directly on the server. + The parameter is an complex array describing the changes to be performed. It is considered for more advanced users, + because it is more compact, so please refer to the latest API documentation for more information.</para> </refsect1> <refsect1> <title>Adding attributes</title> <para> + Adding attrbiute values to an entry is an easy task. You just need to call <function>add</function>! + The parameter is an array whose keys are the attribute names and values the attributes values. + If only one attribute value should be added, the second level may be a string. + If the attribute doesn't exist so far, it will be added, if it exists, the attributes values will be added. </para> <example> <title>Adding attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// Adding several attributes: +$result = $entry->add( + array( + 'sn' => 'Doe', + 'gn' => array('John'), + 'mail' => array('john@doe.org', 'j.doe@example.org') + ) +); ]]></programlisting> </example> @@ -51,11 +138,26 @@ <title>Changing attributes</title> <para> + Changing values is with the <function>replace</function> method as easy as adding values. However, you have to be a little more careful. + The expected parameter is an array describing the new absolute state of the named + attributes. This means, if you specify a <literal>NULL</literal> value for an attribute, + this attribute will get deleted! + You may specify single values as string too. + The keys of the array are expected to be the attributes names. </para> <example> <title>Changing attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// Changing several attributes: +// 'sn' is changed to "Smith", 'gn' gets deleted and mail will +// be changed to te two new adresses +$result = $entry->replace( + array( + 'sn' => 'Smith', + 'gn' => null, + 'mail' => array('smith@example.org', 'smith@example.de') + ) +); ]]></programlisting> </example> @@ -65,11 +167,32 @@ <title>Deleting attributes</title> <para> + Using the <function>delete</function> method you are able to delete specific attributes values as well + as delete a whole attribute. + You need to specify the attribute names as array keys, the array values are the values you want to delete. + If you want to delete whiole attributes, specify them as single level array. + Special care must be taken not to delete the whole entry which will be the case if the parameter array is + omitted or set to <literal>NULL</literal>! + Also, don't mix syntax modes. If you want to delete whole attributes you can't delete specific values from another attribute + in the same function call. </para> <example> <title>Deleting attributes</title> <programlisting role="php"><![CDATA[ -// TODO +// Delete the whole entry: +$result = $entry->delete(); + +// Delete the whole telephone number attribute: +$result = $entry->delete('telephoneNumber'); + +// Delete one specific mail attributes value: +$result = $entry->delete( array('mail' => 'j.doe@example.org') ); + +// Delete mail and telephone attributes as a whole: +$result = $entry->delete( array('mail', 'telephoneNumber') ); + +// Delete two specific mail adresses: +$result = $entry->delete( array('mail' => array('smith@example.org', 'smith@example.de')) ); ]]></programlisting> </example> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-ldap/fetching.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/networking/net-ldap/fetching.xml diff -u peardoc/en/package/networking/net-ldap/fetching.xml:1.1 peardoc/en/package/networking/net-ldap/fetching.xml:1.2 --- peardoc/en/package/networking/net-ldap/fetching.xml:1.1 Tue Jun 26 08:58:03 2007 +++ peardoc/en/package/networking/net-ldap/fetching.xml Tue Jun 26 14:07:01 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.networking.net-ldap.fetching"> <refnamediv> <refname>Fetching entries</refname> @@ -80,7 +80,8 @@ <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> + <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. + You can of course sort ascending (default) or descending - just pass the PHP constant <literal>SORT_ASC</literal> or <literal>SORT_DESC</literal> as second parameter.</entry> </row> <row>