xref: /dokuwiki/lib/plugins/authad/adLDAP/collections/adLDAPCollection.php (revision 76ce1169a0c8cbb18423b1581800b9aa1050ccd5)
1*76ce1169SAndreas Gohr<?php
2*76ce1169SAndreas Gohr/**
3*76ce1169SAndreas Gohr * PHP LDAP CLASS FOR MANIPULATING ACTIVE DIRECTORY
4*76ce1169SAndreas Gohr * Version 4.0.4
5*76ce1169SAndreas Gohr *
6*76ce1169SAndreas Gohr * PHP Version 5 with SSL and LDAP support
7*76ce1169SAndreas Gohr *
8*76ce1169SAndreas Gohr * Written by Scott Barnett, Richard Hyland
9*76ce1169SAndreas Gohr *   email: scott@wiggumworld.com, adldap@richardhyland.com
10*76ce1169SAndreas Gohr *   http://adldap.sourceforge.net/
11*76ce1169SAndreas Gohr *
12*76ce1169SAndreas Gohr * Copyright (c) 2006-2012 Scott Barnett, Richard Hyland
13*76ce1169SAndreas Gohr *
14*76ce1169SAndreas Gohr * We'd appreciate any improvements or additions to be submitted back
15*76ce1169SAndreas Gohr * to benefit the entire community :)
16*76ce1169SAndreas Gohr *
17*76ce1169SAndreas Gohr * This library is free software; you can redistribute it and/or
18*76ce1169SAndreas Gohr * modify it under the terms of the GNU Lesser General Public
19*76ce1169SAndreas Gohr * License as published by the Free Software Foundation; either
20*76ce1169SAndreas Gohr * version 2.1 of the License.
21*76ce1169SAndreas Gohr *
22*76ce1169SAndreas Gohr * This library is distributed in the hope that it will be useful,
23*76ce1169SAndreas Gohr * but WITHOUT ANY WARRANTY; without even the implied warranty of
24*76ce1169SAndreas Gohr * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25*76ce1169SAndreas Gohr * Lesser General Public License for more details.
26*76ce1169SAndreas Gohr *
27*76ce1169SAndreas Gohr * @category ToolsAndUtilities
28*76ce1169SAndreas Gohr * @package adLDAP
29*76ce1169SAndreas Gohr * @subpackage Collection
30*76ce1169SAndreas Gohr * @author Scott Barnett, Richard Hyland
31*76ce1169SAndreas Gohr * @copyright (c) 2006-2012 Scott Barnett, Richard Hyland
32*76ce1169SAndreas Gohr * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPLv2.1
33*76ce1169SAndreas Gohr * @revision $Revision: 97 $
34*76ce1169SAndreas Gohr * @version 4.0.4
35*76ce1169SAndreas Gohr * @link http://adldap.sourceforge.net/
36*76ce1169SAndreas Gohr*/
37*76ce1169SAndreas Gohr
38*76ce1169SAndreas Gohrabstract class adLDAPCollection
39*76ce1169SAndreas Gohr{
40*76ce1169SAndreas Gohr    /**
41*76ce1169SAndreas Gohr    * The current adLDAP connection via dependency injection
42*76ce1169SAndreas Gohr    *
43*76ce1169SAndreas Gohr    * @var adLDAP
44*76ce1169SAndreas Gohr    */
45*76ce1169SAndreas Gohr    protected $adldap;
46*76ce1169SAndreas Gohr
47*76ce1169SAndreas Gohr    /**
48*76ce1169SAndreas Gohr    * The current object being modifed / called
49*76ce1169SAndreas Gohr    *
50*76ce1169SAndreas Gohr    * @var mixed
51*76ce1169SAndreas Gohr    */
52*76ce1169SAndreas Gohr    protected $currentObject;
53*76ce1169SAndreas Gohr
54*76ce1169SAndreas Gohr    /**
55*76ce1169SAndreas Gohr    * The raw info array from Active Directory
56*76ce1169SAndreas Gohr    *
57*76ce1169SAndreas Gohr    * @var array
58*76ce1169SAndreas Gohr    */
59*76ce1169SAndreas Gohr    protected $info;
60*76ce1169SAndreas Gohr
61*76ce1169SAndreas Gohr    public function __construct($info, adLDAP $adldap)
62*76ce1169SAndreas Gohr    {
63*76ce1169SAndreas Gohr        $this->setInfo($info);
64*76ce1169SAndreas Gohr        $this->adldap = $adldap;
65*76ce1169SAndreas Gohr    }
66*76ce1169SAndreas Gohr
67*76ce1169SAndreas Gohr    /**
68*76ce1169SAndreas Gohr    * Set the raw info array from Active Directory
69*76ce1169SAndreas Gohr    *
70*76ce1169SAndreas Gohr    * @param array $info
71*76ce1169SAndreas Gohr    */
72*76ce1169SAndreas Gohr    public function setInfo(array $info)
73*76ce1169SAndreas Gohr    {
74*76ce1169SAndreas Gohr        if ($this->info && sizeof($info) >= 1) {
75*76ce1169SAndreas Gohr            unset($this->info);
76*76ce1169SAndreas Gohr        }
77*76ce1169SAndreas Gohr        $this->info = $info;
78*76ce1169SAndreas Gohr    }
79*76ce1169SAndreas Gohr
80*76ce1169SAndreas Gohr    /**
81*76ce1169SAndreas Gohr    * Magic get method to retrieve data from the raw array in a formatted way
82*76ce1169SAndreas Gohr    *
83*76ce1169SAndreas Gohr    * @param string $attribute
84*76ce1169SAndreas Gohr    * @return mixed
85*76ce1169SAndreas Gohr    */
86*76ce1169SAndreas Gohr    public function __get($attribute)
87*76ce1169SAndreas Gohr    {
88*76ce1169SAndreas Gohr        if (isset($this->info[0]) && is_array($this->info[0])) {
89*76ce1169SAndreas Gohr            foreach ($this->info[0] as $keyAttr => $valueAttr) {
90*76ce1169SAndreas Gohr                if (strtolower($keyAttr) == strtolower($attribute)) {
91*76ce1169SAndreas Gohr                    if ($this->info[0][strtolower($attribute)]['count'] == 1) {
92*76ce1169SAndreas Gohr                        return $this->info[0][strtolower($attribute)][0];
93*76ce1169SAndreas Gohr                    }
94*76ce1169SAndreas Gohr                    else {
95*76ce1169SAndreas Gohr                        $array = array();
96*76ce1169SAndreas Gohr                        foreach ($this->info[0][strtolower($attribute)] as $key => $value) {
97*76ce1169SAndreas Gohr                            if ((string)$key != 'count') {
98*76ce1169SAndreas Gohr                                $array[$key] = $value;
99*76ce1169SAndreas Gohr                            }
100*76ce1169SAndreas Gohr                        }
101*76ce1169SAndreas Gohr                        return $array;
102*76ce1169SAndreas Gohr                    }
103*76ce1169SAndreas Gohr                }
104*76ce1169SAndreas Gohr            }
105*76ce1169SAndreas Gohr        }
106*76ce1169SAndreas Gohr        else {
107*76ce1169SAndreas Gohr            return NULL;
108*76ce1169SAndreas Gohr        }
109*76ce1169SAndreas Gohr    }
110*76ce1169SAndreas Gohr
111*76ce1169SAndreas Gohr    /**
112*76ce1169SAndreas Gohr    * Magic set method to update an attribute
113*76ce1169SAndreas Gohr    *
114*76ce1169SAndreas Gohr    * @param string $attribute
115*76ce1169SAndreas Gohr    * @param string $value
116*76ce1169SAndreas Gohr    * @return bool
117*76ce1169SAndreas Gohr    */
118*76ce1169SAndreas Gohr    abstract public function __set($attribute, $value);
119*76ce1169SAndreas Gohr
120*76ce1169SAndreas Gohr    /**
121*76ce1169SAndreas Gohr    * Magic isset method to check for the existence of an attribute
122*76ce1169SAndreas Gohr    *
123*76ce1169SAndreas Gohr    * @param string $attribute
124*76ce1169SAndreas Gohr    * @return bool
125*76ce1169SAndreas Gohr    */
126*76ce1169SAndreas Gohr    public function __isset($attribute) {
127*76ce1169SAndreas Gohr        if (isset($this->info[0]) && is_array($this->info[0])) {
128*76ce1169SAndreas Gohr            foreach ($this->info[0] as $keyAttr => $valueAttr) {
129*76ce1169SAndreas Gohr                if (strtolower($keyAttr) == strtolower($attribute)) {
130*76ce1169SAndreas Gohr                    return true;
131*76ce1169SAndreas Gohr                }
132*76ce1169SAndreas Gohr            }
133*76ce1169SAndreas Gohr        }
134*76ce1169SAndreas Gohr        return false;
135*76ce1169SAndreas Gohr     }
136*76ce1169SAndreas Gohr}
137*76ce1169SAndreas Gohr?>
138