forked from pear/LiveUser_Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.php
192 lines (180 loc) · 5.67 KB
/
Storage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* A framework for authentication and authorization in PHP applications
*
* LiveUser_Admin is meant to be used with the LiveUser package.
* It is composed of all the classes necessary to administrate
* data used by LiveUser.
*
* You'll be able to add/edit/delete/get things like:
* * Rights
* * Users
* * Groups
* * Areas
* * Applications
* * Subgroups
* * ImpliedRights
*
* And all other entities within LiveUser.
*
* At the moment we support the following storage containers:
* * DB
* * MDB
* * MDB2
*
* But it takes no time to write up your own storage container,
* so if you like to use native mysql functions straight, then it's possible
* to do so in under a hour!
*
* PHP version 4 and 5
*
* LICENSE: This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* @category authentication
* @package LiveUser_Admin
* @author Markus Wolff <[email protected]>
* @author Helgi Þormar Þorbjörnsson <[email protected]>
* @author Lukas Smith <[email protected]>
* @author Arnaud Limbourg <[email protected]>
* @author Christian Dickmann <[email protected]>
* @author Matt Scifo <[email protected]>
* @author Bjoern Kraus <[email protected]>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version CVS: $Id$
* @link http://pear.php.net/LiveUser_Admin
*/
/**
* This is core base class for all LiveUser admin storage classes that is meant
* for internal use only.
*
* @category authentication
* @package LiveUser_Admin
* @author Lukas Smith <[email protected]>
* @author Bjoern Kraus <[email protected]>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version Release: @package_version@
* @link http://pear.php.net/LiveUser_Admin
*/
class LiveUser_Admin_Storage
{
/**
* Table configuration
*
* @var array
* @access public
*/
var $tables = array();
/**
* All fields with their types
*
* @var array
* @access public
*/
var $fields = array();
/**
* All fields with their alias
*
* @var array
* @access public
*/
var $alias = array();
/**
* Constructor
*
* @access protected
* @return void
*/
function LiveUser_Admin_Storage()
{
$this->stack = &PEAR_ErrorStack::singleton('LiveUser_Admin');
}
/**
* Initializes database storage container.
* Goes through the storage config and turns each value into
* a var
*
* @param array Storage Configuration
* @param array containing the database structure (tables, fields, alias)
* @return bool true on success and false on failure
*
* @access public
*/
function init(&$storageConf, $structure)
{
if (is_array($storageConf)) {
$keys = array_keys($storageConf);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->$key =& $storageConf[$key];
}
}
}
if (empty($this->tables)) {
$this->tables = $structure['tables'];
} else {
$this->tables = LiveUser::arrayMergeClobber($structure['tables'], $this->tables);
}
if (empty($this->fields)) {
$this->fields = $structure['fields'];
} else {
$this->fields = LiveUser::arrayMergeClobber($structure['fields'], $this->fields);
}
if (empty($this->alias)) {
$this->alias = $structure['alias'];
} else {
$this->alias = LiveUser::arrayMergeClobber($structure['alias'], $this->alias);
}
return true;
}
/**
* Static method to set defaults into a select params array
*
* @param array params array
* @return array params array
*
* @access public
*/
function setSelectDefaultParams($params)
{
if (!is_array($params)) {
PEAR_ErrorStack::staticPush('LiveUser_Admin', LIVEUSER_ADMIN_ERROR,
'exception', array(), 'Parameters must be an array but is of type: '.gettype($params));
}
$params['fields'] = empty($params['fields']) ? array('*') : $params['fields'];
$params['with'] = empty($params['with']) ? array() : $params['with'];
$params['filters'] = empty($params['filters']) ? array() : $params['filters'];
$params['orders'] = empty($params['orders']) ? array() : $params['orders'];
$params['rekey'] = empty($params['rekey']) ? false : $params['rekey'];
$params['group'] = empty($params['group']) ? false : $params['group'];
$params['limit'] = empty($params['limit']) ? null : $params['limit'];
$params['offset'] = empty($params['offset']) ? null : $params['offset'];
$params['select'] = empty($params['select']) ? 'all' : $params['select'];
return $params;
}
/**
* properly disconnect from resources
*
* @access public
*/
function disconnect()
{
}
}
?>