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