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

Source for file Search.php

Documentation is available at Search.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: Tarjej Huse                                                     |
  23. // +--------------------------------------------------------------------------+
  24. //
  25. // $Id: Search.php,v 1.4.2.3 2005/03/01 12:27:43 jw Exp $
  26.  
  27. /**
  28.  * Result set of an LDAP search
  29.  *
  30.  * @author  Tarjei Huse
  31.  * @version $Revision: 1.4.2.3 $
  32.  * @package Net_LDAP
  33.  */
  34. class Net_LDAP_Search extends PEAR
  35. {
  36.     /**
  37.      * Search result identifier
  38.      *
  39.      * @access private
  40.      * @var resource 
  41.      */
  42.     var $_search;
  43.     
  44.     /**
  45.      * LDAP resource link
  46.      *
  47.      * @access private
  48.      * @var resource 
  49.      */
  50.     var $_link;
  51.  
  52.     /**
  53.      * Array of entries
  54.      *
  55.      * @access private
  56.      * @var array 
  57.      */
  58.     var $_entries = array();
  59.     
  60.     /**
  61.      * Result entry identifier
  62.      *
  63.      * @access private
  64.      * @var resource 
  65.      */
  66.     var $_elink = null;
  67.  
  68.     /**
  69.      * The errorcode the search got
  70.      * 
  71.      * Some errorcodes might be of interest, but might not be best handled as errors.
  72.      * examples: 4 - LDAP_SIZELIMIT_EXCEEDED - indecates a huge search.
  73.      *               Incomplete results are returned. If you just want to check if there's anything in the search.
  74.      *               than this is a point to handle.
  75.      *           32 - no such object - search here returns a count of 0.
  76.      *          
  77.      * @access private
  78.      * @var int 
  79.      */
  80.     var $_errorCode = 0; // if not set - sucess!
  81.     
  82.    /** 
  83.     * Constructor
  84.     *
  85.     * @access protected
  86.     * @param resource Search result identifier
  87.     * @param resource Link identifier
  88.     */
  89.     function Net_LDAP_Search (&$search&$link)
  90.     {    
  91.         $this->_setSearch($search$link);
  92.         $this->_errorCode = ldap_errno($link);
  93.     }
  94.  
  95.     /**
  96.      * Returns an assosiative array of entry objects
  97.      *
  98.      * @return array Array of entry objects.
  99.      */
  100.     function entries()
  101.     {
  102.         if ($this->count(== 0{
  103.             return array();
  104.         }
  105.         
  106.         $this->_elink @ldap_first_entry$this->_link,$this->_search);
  107.         $entry = new Net_LDAP_Entry($this->_link,    
  108.                                     @ldap_get_dn($this->_link$this->_elink),
  109.                                     @ldap_get_attributes($this->_link$this->_elink));
  110.         array_push($this->_entries$entry);
  111.  
  112.         while ($this->_elink @ldap_next_entry($this->_link,$this->_elink)) {
  113.             $entry = new Net_LDAP_Entry($this->_link,
  114.                                         @ldap_get_dn($this->_link$this->_elink),
  115.                                         @ldap_get_attributes($this->_link$this->_elink));
  116.             array_push($this->_entries$entry);
  117.         }
  118.         return $this->_entries;
  119.     }
  120.    
  121.     /**
  122.      * Get the next entry in the searchresult.
  123.      *
  124.      * @return mixed Net_LDAP_Entry object or false
  125.      */
  126.     function shiftEntry()
  127.     {
  128.         if ($this->count(== 0 {
  129.             return false;
  130.         }
  131.  
  132.         if (is_null($this->_elink)) {
  133.             $this->_elink @ldap_first_entry($this->_link$this->_search);
  134.             $entry = new Net_LDAP_Entry($this->_link,
  135.                                         ldap_get_dn($this->_link$this->_elink),
  136.                                         ldap_get_attributes($this->_link$this->_elink));
  137.         else {
  138.             if (!$this->_elink = ldap_next_entry($this->_link$this->_elink)) {
  139.                 return false;
  140.             }
  141.             $entry = new Net_LDAP_Entry($this->_link,
  142.                                         ldap_get_dn($this->_link,$this->_elink),
  143.                                         ldap_get_attributes($this->_link,$this->_elink));
  144.         }
  145.         return $entry;
  146.     }
  147.     
  148.     /**
  149.      * alias function of shiftEntry() for perl-ldap interface
  150.      * 
  151.      * @see shiftEntry()
  152.      */
  153.     function shift_entry(
  154.     {
  155.         $args func_get_args();
  156.         return call_user_func_array(array($this'shiftEntry')$args);
  157.     }
  158.    
  159.     /**
  160.      * Retrieve the last entry of the searchset. NOT IMPLEMENTED
  161.      *
  162.      * @return object Net_LDAP_Error 
  163.      */
  164.     function pop_entry (
  165.     {
  166.         $this->raiseError("Not implemented");
  167.     }
  168.     
  169.     /**
  170.      * Return entries sorted NOT IMPLEMENTED
  171.      *
  172.      * @param array Array of sort attributes
  173.      * @return object Net_LDAP_Error 
  174.      */
  175.     function sorted ($attrs = array()) 
  176.     {
  177.         $this->raiseError("Not impelented");
  178.     }
  179.     
  180.    /** 
  181.     * Return entries as object NOT IMPLEMENTED
  182.     *
  183.     * @return object Net_LDAP_Error 
  184.     */
  185.     function as_struct ()
  186.     {
  187.         $this->raiseError("Not implemented");
  188.     }
  189.  
  190.    /**
  191.     * Set the searchobjects resourcelinks
  192.     *
  193.     * @access private
  194.     * @param resource Search result identifier
  195.     * @param resource Resource link identifier
  196.     */
  197.     function _setSearch(&$search,&$link)
  198.     {      
  199.         $this->_search $search;
  200.         $this->_link   $link;
  201.     }
  202.    
  203.    /**
  204.     * Returns the number of entries in the searchresult
  205.     *
  206.     * @return int Number of entries in search.
  207.     */
  208.     function count()
  209.     {
  210.         /* this catches the situation where OL returned errno 32 = no such object! */
  211.         if (!$this->_search{
  212.             return 0;
  213.         }
  214.         return @ldap_count_entries($this->_link$this->_search);
  215.     }
  216.  
  217.     /**
  218.      * Get the errorcode the object got in its search.
  219.      *
  220.      * @return int The ldap error number.
  221.      */
  222.     function getErrorCode()
  223.     {
  224.         return $this->_errorCode;
  225.     }
  226.     
  227.    /** Destructor
  228.     *
  229.     * @access protected
  230.     */
  231.     function _Net_LDAP_Search(
  232.     {
  233.         @ldap_free_result($this->_search);
  234.     }
  235.     
  236.    /** 
  237.     * Closes search result
  238.     */
  239.     function done()
  240.     {
  241.         $this->_Net_LDAP_Search();
  242.     }
  243. }
  244.  
  245. ?>

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