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.7 2006/12/15 11:45:35 beni 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.7 $
  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 Net_LDAP Reference to Net_LDAP object
  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 $attributes Array of attributes
  78.      * @return array Array of UTF8 encoded attributes
  79.      * @todo the code is doubled in class Net_LDAP! Regarding to Jan utf8-stuff should be done inside Net_LDAP so THIS function is obsolete
  80.      * @obsolete
  81.      */
  82.     function utf8Encode($attributes)
  83.     {
  84.         return $this->_utf8($attributes'utf8_encode');
  85.     }
  86.  
  87.     /**
  88.      * Decodes the given attribute values
  89.      *
  90.      * @access public
  91.      * @param array $attributes Array of attributes
  92.      * @return array Array with decoded attribute values
  93.      * @todo the code is doubled in class Net_LDAP! Regarding to Jan utf8-stuff should be done inside Net_LDAP so THIS function is obsolete
  94.      * @obsolete
  95.      */
  96.     function utf8Decode($attributes)
  97.     {
  98.         return $this->_utf8($attributes'utf8_decode');
  99.     }
  100.  
  101.     /**
  102.      * Encodes or decodes attribute values if needed
  103.      *
  104.      * @access private
  105.      * @param array $attributes Array of attributes
  106.      * @param array $function Function to apply to attribute values
  107.      * @return array Array of attributes with function applied to values
  108.      * @todo the code is doubled in class Net_LDAP! Regarding to Jan utf8-stuff should be done inside Net_LDAP so THIS function is obsolete
  109.      * @obsolete
  110.      */
  111.     function _utf8($attributes$function)
  112.     {
  113.         if (!$this->_ldap || !$this->_schema || !function_exists($function)) {
  114.             return $attributes;
  115.         }
  116.         if (is_array($attributes&& count($attributes> 0{
  117.             foreach$attributes as $k => $v {
  118.                 $attr $this->_schema->get('attribute'$k);
  119.                 if (Net_LDAP::isError($attr)) {
  120.                     continue;
  121.                 }
  122.                 if (false !== strpos($attr['syntax']'1.3.6.1.4.1.1466.115.121.1.15')) {
  123.                     if (is_array($v)) {
  124.                         foreach ($v as $ak => $av {
  125.                             $v[$akcall_user_func($function$av );
  126.                         }
  127.                     else {
  128.                         $v call_user_func($function$v);
  129.                     }
  130.                 }
  131.                 $attributes[$k$v;
  132.             }
  133.         }
  134.         return $attributes;
  135.     }
  136. }
  137.  
  138. ?>

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