Net_LDAP
[ class tree: Net_LDAP ] [ index: Net_LDAP ] [ all elements ]

Source for file Util.php

Documentation is available at Util.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +--------------------------------------------------------------------------+
  4. // | Net_LDAP                                                                 |
  5. // +--------------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                    |
  7. // +--------------------------------------------------------------------------+
  8. // | This library is free software; you can redistribute it and/or            |
  9. // | modify it under the terms of the GNU Lesser General Public               |
  10. // | License as published by the Free Software Foundation; either             |
  11. // | version 2.1 of the License, or (at your option) any later version.       |
  12. // |                                                                          |
  13. // | This library is distributed in the hope that it will be useful,          |
  14. // | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
  15. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        |
  16. // | Lesser General Public License for more details.                          |
  17. // |                                                                          |
  18. // | You should have received a copy of the GNU Lesser General Public         |
  19. // | License along with this library; if not, write to the Free Software      |
  20. // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA |
  21. // +--------------------------------------------------------------------------+
  22. // | Authors: Jan Wagner                                                      |
  23. // +--------------------------------------------------------------------------+
  24. //
  25. // $Id: Util.php,v 1.4.2.1 2004/03/08 11:42:45 jw Exp $
  26.   
  27. /**
  28.  * Utility Class for Net_LDAP
  29.  *
  30.  * @package Net_LDAP
  31.  * @author Jan Wagner <wagner@netsols.de>
  32.  * @version $Revision: 1.4.2.1 $
  33.  */
  34. class Net_LDAP_Util extends PEAR 
  35. {
  36.     /**
  37.      * Reference to LDAP object
  38.      *
  39.      * @access private
  40.      * @var object Net_LDAP 
  41.      */
  42.     var $_ldap = null;
  43.     
  44.     /**
  45.      * Net_LDAP_Schema object
  46.      *
  47.      * @access private
  48.      * @var object Net_LDAP_Schema 
  49.      */
  50.     var $_schema = null;
  51.     
  52.     /**
  53.      * Constructur
  54.      *
  55.      * Takes an LDAP object by reference and saves it. Then the schema will be fetched.
  56.      *
  57.      * @access public
  58.      * @param object Net_LDAP 
  59.      */
  60.     function Net_LDAP_Util(&$ldap)
  61.     {
  62.         if (is_object($ldap&& (strtolower(get_class($ldap)) == 'net_ldap')) {
  63.             $this->_ldap $ldap;
  64.             $this->_schema $this->_ldap->schema();
  65.             if (Net_LDAP::isError($this->_schema)) $this->_schema = null;
  66.         }
  67.     }
  68.     
  69.     /**
  70.      * Encodes given attributes to UTF8 if needed
  71.      *
  72.      * This function takes attributes in an array and then checks against the schema if they need
  73.      * UTF8 encoding. If that is so, they will be encoded. An encoded array will be returned and
  74.      * can be used for adding or modifying.
  75.      *
  76.      * @access public
  77.      * @param array Array of attributes
  78.      * @return array Array of UTF8 encoded attributes
  79.      */
  80.     function utf8Encode($attributes)
  81.     {
  82.         return $this->_utf8($attributes'utf8_encode');
  83.     }
  84.     
  85.     /**
  86.      * Decodes the given attribute values
  87.      *
  88.      * @access public
  89.      * @param array Array of attributes
  90.      * @return array Array with decoded attribute values
  91.      */
  92.     function utf8Decode($attributes)
  93.     {
  94.         return $this->_utf8($attributes'utf8_decode');
  95.     }
  96.     
  97.     /**
  98.      * Encodes or decodes attribute values if needed
  99.      *
  100.      * @access private
  101.      * @param array Array of attributes
  102.      * @param array Function to apply to attribute values
  103.      * @return array Array of attributes with function applied to values
  104.      */
  105.     function _utf8($attributes$function)
  106.     {
  107.         if (!$this->_ldap || !$this->_schema || !function_exists($function)) {
  108.             return $attributes;
  109.         }
  110.         if (is_array($attributes&& count($attributes> 0{
  111.             foreach$attributes as $k => $v {
  112.                 $attr $this->_schema->get('attribute'$k);
  113.                 if (Net_LDAP::isError($attr)) {
  114.                     continue;
  115.                 }                
  116.                 if (false !== strpos($attr['syntax']'1.3.6.1.4.1.1466.115.121.1.15')) {                    
  117.                     if (is_array($v)) {
  118.                         foreach ($v as $ak => $av {
  119.                             $v[$akcall_user_func($function$av );
  120.                         }
  121.                     else {
  122.                         $v call_user_func($function$v);
  123.                     }
  124.                 }
  125.                 $attributes[$k$v;
  126.             }
  127.         }
  128.         return $attributes;    
  129.     }    
  130. }
  131.  
  132. ?>

Documentation generated on Mon, 11 Mar 2019 14:26:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.