21 |
rodolico |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
Copyright (c) 2021, Daily Data, Inc. Redistribution and use in
|
|
|
5 |
source and binary forms, with or without modification, are permitted
|
|
|
6 |
provided that the following conditions are met:
|
|
|
7 |
|
|
|
8 |
* Redistributions of source code must retain the above copyright
|
|
|
9 |
notice, this list of conditions and the following disclaimer.
|
|
|
10 |
* Redistributions in binary form must reproduce the above copyright
|
|
|
11 |
notice, this list of conditions and the following disclaimer in the
|
|
|
12 |
documentation and/or other materials provided with the distribution.
|
|
|
13 |
|
|
|
14 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
15 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
16 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
17 |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
18 |
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
19 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
20 |
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
21 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
22 |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
23 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
24 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
25 |
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
/*
|
|
|
29 |
* UsersDataSource.class.php
|
|
|
30 |
*
|
|
|
31 |
* Authors: R. W. Rodolico
|
|
|
32 |
*
|
|
|
33 |
*/
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* usersDataSource class
|
|
|
37 |
*
|
|
|
38 |
* usersDataSource provides the data access capabilities for the Users
|
|
|
39 |
* class.
|
|
|
40 |
*
|
|
|
41 |
* To build a data access class for Users, the following 5 methods must
|
|
|
42 |
* exist.
|
|
|
43 |
* getPassword(username)
|
|
|
44 |
* getAllUsers()
|
|
|
45 |
* getARecord
|
|
|
46 |
* update
|
|
|
47 |
*
|
|
|
48 |
* Additionally, where appropriate, the following function is useful
|
|
|
49 |
* buildTable()
|
|
|
50 |
*
|
|
|
51 |
* This particular instance provides an interface to MySQL using
|
|
|
52 |
* the mysqli libraries.
|
|
|
53 |
*
|
|
|
54 |
* Create an instance of this, then pass the variable to several Users
|
|
|
55 |
* calls.
|
|
|
56 |
*
|
|
|
57 |
* @author R. W. Rodolico <rodo@unixservertech.com>
|
|
|
58 |
*
|
|
|
59 |
* @version 0.9.0 (beta)
|
|
|
60 |
* @copyright 2021 Daily Data, Inc.
|
|
|
61 |
*
|
|
|
62 |
*/
|
|
|
63 |
|
|
|
64 |
abstract class usersDataSource {
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* @var string[] $configuration Contains the configuration for the class
|
|
|
68 |
*
|
|
|
69 |
* May be modified by the calling program. Must be replicated in userDataSource class
|
|
|
70 |
*/
|
|
|
71 |
protected $configuration = array();
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* constructor for an instance of the class
|
|
|
75 |
*
|
|
|
76 |
* If $dbConnection is not null, will be used for database access
|
|
|
77 |
* If $dbLoginInfo is not null, will override $dbConnection, make
|
|
|
78 |
* a new connection and use that.
|
|
|
79 |
*
|
|
|
80 |
* If $dbDef is set, will be merged with $configuration
|
|
|
81 |
*
|
|
|
82 |
* @param mysqli $dbConnection Existing mysqli database connection
|
|
|
83 |
* @param string[] $dbDef Array to be merged with $configuration
|
|
|
84 |
* @param string[] $dbLoginInfo Array containing username, hostname, etc.. to make mysqli connection_aborted
|
|
|
85 |
*
|
|
|
86 |
* @return null
|
|
|
87 |
*
|
|
|
88 |
*/
|
|
|
89 |
public function __construct( $dbDef = array() ) {
|
|
|
90 |
if ( $dbDef ) {
|
|
|
91 |
$this->configuration = array_merge_recursive( $this->configuration, $dbDef );
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Get a record from the database
|
|
|
97 |
*
|
|
|
98 |
* Gets a single record from the database which matches $field containing
|
|
|
99 |
* $username. If more than one record is returned, will return the first
|
|
|
100 |
* one
|
|
|
101 |
*
|
|
|
102 |
* @param string[] $whereFields column=>value pairs for where clause
|
|
|
103 |
* @param string[] $fieldList a list of columns to return. If empty, returns all columns
|
|
|
104 |
*
|
|
|
105 |
* @return string[] a hash containing fieldname=>value pairs from fetch_assoc
|
|
|
106 |
*
|
|
|
107 |
*/
|
|
|
108 |
abstract public function getARecord( $whereFields, $fieldList = null );
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Retrieves the password field from table
|
|
|
112 |
*
|
|
|
113 |
* Note that the password is stored as a hash in the table
|
|
|
114 |
*
|
|
|
115 |
* @param string $username username used to find record
|
|
|
116 |
* @return string[] an array of values key/value pairs
|
|
|
117 |
*/
|
|
|
118 |
abstract public function getPassword( $username );
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* updates row in database with $newData
|
|
|
122 |
*
|
|
|
123 |
* @param string[] $newData fieldname/value pairs to be updated in table
|
|
|
124 |
*
|
|
|
125 |
* @return mysqli_result|bool The mysqli result from a query
|
|
|
126 |
*/
|
|
|
127 |
abstract public function update ( $newData );
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* retrieves all users from the database
|
|
|
131 |
*
|
|
|
132 |
* Retrieves all data for all users from table
|
|
|
133 |
*
|
|
|
134 |
* @return string[] array of array of rows/columns
|
|
|
135 |
*/
|
|
|
136 |
abstract public function getAllUsers();
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
?>
|