Skip to content

Commit 9b37518

Browse files
committed
Accept HexUuidLiteral as $userid
1 parent 996b97e commit 9b37518

File tree

6 files changed

+72
-64
lines changed

6 files changed

+72
-64
lines changed

src/Interfaces/UsersInterface.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use ByJG\Authenticate\Model\UserModel;
99
use ByJG\Authenticate\Model\UserPropertiesModel;
1010
use ByJG\JwtWrapper\JwtWrapper;
11+
use ByJG\MicroOrm\Literal\HexUuidLiteral;
1112

1213
/**
1314
* IUsersBase is an Interface to Store and Retrive USERS from an AnyDataset or a DBDataset structure.
@@ -49,10 +50,10 @@ public function getUser(IteratorFilter $filter): UserModel|null;
4950
/**
5051
* Enter description here...
5152
*
52-
* @param string $userid
53+
* @param string|HexUuidLiteral|int $userid
5354
* @return UserModel|null
5455
*/
55-
public function getById(string $userid): UserModel|null;
56+
public function getById(string|HexUuidLiteral|int $userid): UserModel|null;
5657

5758
/**
5859
* @desc Get the user based on his email.
@@ -92,51 +93,51 @@ public function isValidUser(string $userName, string $password): UserModel|null;
9293

9394
/**
9495
*
95-
* @param string $userId
96+
* @param string|int|HexUuidLiteral $userId
9697
* @return bool
9798
*/
98-
public function isAdmin(string $userId): bool;
99+
public function isAdmin(string|HexUuidLiteral|int $userId): bool;
99100

100101
/**
101102
* @desc Check if the user have rights to edit specific site.
102-
* @param string $userId
103+
* @param string|int|HexUuidLiteral|null $userId
103104
* @param string $propertyName
104105
* @param string|null $value
105106
* @return bool True, if it has the property; false, otherwisebool
106107
*/
107-
public function hasProperty(string $userId, string $propertyName, string $value = null): bool;
108+
public function hasProperty(string|int|HexUuidLiteral|null $userId, string $propertyName, string $value = null): bool;
108109

109110
/**
110111
* @desc Return all sites from a specific user
111-
* @param string $userId
112+
* @param string|int|HexUuidLiteral $userId
112113
* @param string $propertyName
113114
* @return UserPropertiesModel|array<array-key, mixed>|null|string String vector with all sites
114115
*/
115-
public function getProperty(string $userId, string $propertyName): array|string|\ByJG\Authenticate\Model\UserPropertiesModel|null;
116+
public function getProperty(string|HexUuidLiteral|int $userId, string $propertyName): array|string|\ByJG\Authenticate\Model\UserPropertiesModel|null;
116117

117118
/**
118119
*
119-
* @param string $userId
120+
* @param string|int|HexUuidLiteral $userId
120121
* @param string $propertyName
121122
* @param string|null $value
122123
*/
123-
public function addProperty(string $userId, string $propertyName, string|null $value): bool;
124+
public function addProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value): bool;
124125

125126
/**
126127
*
127-
* @param string $userId
128+
* @param string|int|HexUuidLiteral $userId
128129
* @param string $propertyName
129130
* @param string|null $value
130131
*/
131-
public function setProperty(string $userId, string $propertyName, string|null $value): bool;
132+
public function setProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value): bool;
132133

133134
/**
134135
*
135-
* @param string $userId
136+
* @param string|int|HexUuidLiteral $userId
136137
* @param string $propertyName
137138
* @param string|null $value
138139
*/
139-
public function removeProperty(string $userId, string $propertyName, string|null $value = null): bool;
140+
public function removeProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value = null): bool;
140141

141142
/**
142143
* @desc Remove a specific site from all users
@@ -187,8 +188,8 @@ public function getUserDefinition(): UserDefinition;
187188
public function getUserPropertiesDefinition(): UserPropertiesDefinition;
188189

189190
/**
190-
* @param string $userid
191+
* @param string|int|HexUuidLiteral $userid
191192
* @return bool
192193
*/
193-
public function removeUserById(string $userid): bool;
194+
public function removeUserById(string|HexUuidLiteral|int $userid): bool;
194195
}

src/Model/UserModel.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace ByJG\Authenticate\Model;
44

55
use ByJG\Authenticate\Definition\PasswordDefinition;
6+
use ByJG\MicroOrm\Literal\HexUuidLiteral;
67
use InvalidArgumentException;
78

89
class UserModel
910
{
10-
protected ?string $userid = null;
11+
protected string|int|HexUuidLiteral|null $userid = null;
1112
protected ?string $name = null;
1213
protected ?string $email = null;
1314
protected ?string $username = null;
@@ -39,17 +40,17 @@ public function __construct(string $name = "", string $email = "", string $usern
3940

4041

4142
/**
42-
* @return string|null
43+
* @return string|int|HexUuidLiteral|null
4344
*/
44-
public function getUserid(): ?string
45+
public function getUserid(): string|int|HexUuidLiteral|null
4546
{
4647
return $this->userid;
4748
}
4849

4950
/**
50-
* @param string|null $userid
51+
* @param string|int|HexUuidLiteral|null $userid
5152
*/
52-
public function setUserid(?string $userid): void
53+
public function setUserid(string|int|HexUuidLiteral|null $userid): void
5354
{
5455
$this->userid = $userid;
5556
}

src/Model/UserPropertiesModel.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace ByJG\Authenticate\Model;
44

5+
use ByJG\MicroOrm\Literal\HexUuidLiteral;
6+
57
class UserPropertiesModel
68
{
7-
protected ?string $userid = null;
9+
protected string|int|HexUuidLiteral|null $userid = null;
810
protected ?string $id = null;
911
protected ?string $name = null;
1012
protected ?string $value = null;
@@ -22,17 +24,17 @@ public function __construct(string $name = "", string $value = "")
2224
}
2325

2426
/**
25-
* @return string|null
27+
* @return string|int|HexUuidLiteral|null
2628
*/
27-
public function getUserid(): ?string
29+
public function getUserid(): string|int|HexUuidLiteral|null
2830
{
2931
return $this->userid;
3032
}
3133

3234
/**
33-
* @param string|null $userid
35+
* @param string|int|HexUuidLiteral|null $userid
3436
*/
35-
public function setUserid(?string $userid): void
37+
public function setUserid(string|int|HexUuidLiteral|null $userid): void
3638
{
3739
$this->userid = $userid;
3840
}

src/UsersAnyDataset.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use ByJG\Authenticate\Exception\UserNotFoundException;
1515
use ByJG\Authenticate\Model\UserModel;
1616
use ByJG\Authenticate\Model\UserPropertiesModel;
17+
use ByJG\MicroOrm\Literal\HexUuidLiteral;
1718
use ByJG\Serializer\Exception\InvalidArgumentException;
1819
use ByJG\XmlUtil\Exception\FileException;
1920

@@ -175,7 +176,7 @@ public function getUsersByPropertySet(array $propertiesArray): array
175176
}
176177

177178
/**
178-
* @param string $userId
179+
* @param string|int|HexUuidLiteral $userId
179180
* @param string $propertyName
180181
* @param string|null $value
181182
* @return boolean
@@ -185,7 +186,7 @@ public function getUsersByPropertySet(array $propertiesArray): array
185186
* @throws UserExistsException
186187
* @throws UserNotFoundException
187188
*/
188-
public function addProperty(string $userId, string $propertyName, string|null $value): bool
189+
public function addProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value): bool
189190
{
190191
//anydataset.Row
191192
$user = $this->getById($userId);
@@ -206,7 +207,7 @@ public function addProperty(string $userId, string $propertyName, string|null $v
206207
* @throws UserExistsException
207208
* @throws FileException
208209
*/
209-
public function setProperty(string $userId, string $propertyName, string|null $value): bool
210+
public function setProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value): bool
210211
{
211212
$user = $this->getById($userId);
212213
if ($user !== null) {
@@ -218,7 +219,7 @@ public function setProperty(string $userId, string $propertyName, string|null $v
218219
}
219220

220221
/**
221-
* @param string $userId
222+
* @param string|int|HexUuidLiteral $userId
222223
* @param string $propertyName
223224
* @param string|null $value
224225
* @return boolean
@@ -227,7 +228,7 @@ public function setProperty(string $userId, string $propertyName, string|null $v
227228
* @throws InvalidArgumentException
228229
* @throws UserExistsException
229230
*/
230-
public function removeProperty(string $userId, string $propertyName, string|null $value = null): bool
231+
public function removeProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value = null): bool
231232
{
232233
$user = $this->getById($userId);
233234
if (!empty($user)) {
@@ -295,11 +296,11 @@ private function createUserModel(Row $row): UserModel
295296
}
296297

297298
/**
298-
* @param string $userid
299+
* @param string|HexUuidLiteral|int $userid
299300
* @return bool
300301
* @throws InvalidArgumentException
301302
*/
302-
public function removeUserById(string $userid): bool
303+
public function removeUserById(string|HexUuidLiteral|int $userid): bool
303304
{
304305
$iteratorFilter = new IteratorFilter();
305306
$iteratorFilter->and($this->getUserDefinition()->getUserid(), Relation::EQUAL, $userid);

src/UsersBase.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use ByJG\Authenticate\Model\UserPropertiesModel;
1515
use ByJG\JwtWrapper\JwtWrapper;
1616
use ByJG\JwtWrapper\JwtWrapperException;
17+
use ByJG\MicroOrm\Literal\HexUuidLiteral;
18+
use ByJG\Serializer\Exception\InvalidArgumentException;
1719

1820
/**
1921
* Base implementation to search and handle users in XMLNuke.
@@ -84,7 +86,7 @@ public function addUser(string $name, string $userName, string $email, string $p
8486
* @param UserModel $model
8587
* @return bool
8688
* @throws UserExistsException
87-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
89+
* @throws InvalidArgumentException
8890
*/
8991
public function canAddUser(UserModel $model): bool
9092
{
@@ -115,7 +117,7 @@ abstract public function getUser(IteratorFilter $filter): UserModel|null;
115117
*
116118
* @param string $email
117119
* @return UserModel|null
118-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
120+
* @throws InvalidArgumentException
119121
*/
120122
public function getByEmail(string $email): UserModel|null
121123
{
@@ -130,7 +132,7 @@ public function getByEmail(string $email): UserModel|null
130132
*
131133
* @param string $username
132134
* @return UserModel|null
133-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
135+
* @throws InvalidArgumentException
134136
*/
135137
public function getByUsername(string $username): UserModel|null
136138
{
@@ -158,11 +160,11 @@ public function getByLoginField(string $login): UserModel|null
158160
* Get the user based on his id.
159161
* Return Row if user was found; null, otherwise
160162
*
161-
* @param string $userid
163+
* @param string|HexUuidLiteral|int $userid
162164
* @return UserModel|null
163-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
165+
* @throws InvalidArgumentException
164166
*/
165-
public function getById(string $userid): UserModel|null
167+
public function getById(string|HexUuidLiteral|int $userid): UserModel|null
166168
{
167169
$filter = new IteratorFilter();
168170
$filter->and($this->getUserDefinition()->getUserid(), Relation::EQUAL, $userid);
@@ -184,7 +186,7 @@ abstract public function removeByLoginField(string $login): bool;
184186
* @param string $userName User login
185187
* @param string $password Plain text password
186188
* @return UserModel|null
187-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
189+
* @throws InvalidArgumentException
188190
*/
189191
public function isValidUser(string $userName, string $password): UserModel|null
190192
{
@@ -203,14 +205,14 @@ public function isValidUser(string $userName, string $password): UserModel|null
203205
* Check if the user have a property and it has a specific value.
204206
* Return True if you have rights; false, otherwise
205207
*
206-
* @param string $userId User identification
208+
* @param string|int|HexUuidLiteral|null $userId User identification
207209
* @param string $propertyName
208210
* @param string|null $value Property value
209211
* @return bool
210212
* @throws UserNotFoundException
211-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
213+
* @throws InvalidArgumentException
212214
*/
213-
public function hasProperty(string $userId, string $propertyName, string $value = null): bool
215+
public function hasProperty(string|int|HexUuidLiteral|null $userId, string $propertyName, string $value = null): bool
214216
{
215217
//anydataset.Row
216218
$user = $this->getById($userId);
@@ -240,13 +242,13 @@ public function hasProperty(string $userId, string $propertyName, string $value
240242
* Return all sites from a specific user
241243
* Return String vector with all sites
242244
*
243-
* @param string $userId User ID
245+
* @param string|int|HexUuidLiteral $userId User ID
244246
* @param string $propertyName Property name
245247
* @return array|string|UserPropertiesModel|null
246248
* @throws UserNotFoundException
247-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
249+
* @throws InvalidArgumentException
248250
*/
249-
public function getProperty(string $userId, string $propertyName): array|string|UserPropertiesModel|null
251+
public function getProperty(string|HexUuidLiteral|int $userId, string $propertyName): array|string|UserPropertiesModel|null
250252
{
251253
$user = $this->getById($userId);
252254
if ($user !== null) {
@@ -268,22 +270,22 @@ abstract public function getUsersByPropertySet(array $propertiesArray): array;
268270

269271
/**
270272
*
271-
* @param string $userId
273+
* @param string|int|HexUuidLiteral $userId
272274
* @param string $propertyName
273275
* @param string|null $value
274276
*/
275-
abstract public function addProperty(string $userId, string $propertyName, string|null $value): bool;
277+
abstract public function addProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value): bool;
276278

277279
/**
278280
* Remove a specific site from user
279281
* Return True or false
280282
*
281-
* @param string $userId User login
283+
* @param string|int|HexUuidLiteral $userId User login
282284
* @param string $propertyName Property name
283285
* @param string|null $value Property value with a site
284286
* @return bool
285287
* */
286-
abstract public function removeProperty(string $userId, string $propertyName, string|null $value = null): bool;
288+
abstract public function removeProperty(string|HexUuidLiteral|int $userId, string $propertyName, string|null $value = null): bool;
287289

288290
/**
289291
* Remove a specific site from all users
@@ -296,12 +298,12 @@ abstract public function removeProperty(string $userId, string $propertyName, st
296298
abstract public function removeAllProperties(string $propertyName, string|null $value = null): void;
297299

298300
/**
299-
* @param string $userId
301+
* @param string|int|HexUuidLiteral $userId
300302
* @return bool
301303
* @throws UserNotFoundException
302-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
304+
* @throws InvalidArgumentException
303305
*/
304-
public function isAdmin(string $userId): bool
306+
public function isAdmin(string|HexUuidLiteral|int $userId): bool
305307
{
306308
$user = $this->getById($userId);
307309

@@ -325,7 +327,7 @@ public function isAdmin(string $userId): bool
325327
* @param array $updateTokenInfo
326328
* @return string|null the TOKEN or false if you don't.
327329
* @throws UserNotFoundException
328-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
330+
* @throws InvalidArgumentException
329331
*/
330332
public function createAuthToken(
331333
string $login,
@@ -394,7 +396,7 @@ public function isValidToken(string $login, JwtWrapper $jwtWrapper, string $toke
394396
}
395397

396398
/**
397-
* @param string $userid
399+
* @param string|int|HexUuidLiteral $userid
398400
*/
399-
abstract public function removeUserById(string $userid): bool;
401+
abstract public function removeUserById(string|HexUuidLiteral|int $userid): bool;
400402
}

0 commit comments

Comments
 (0)