Skip to content

Commit 737eee7

Browse files
committed
improved PHPDoc descriptions
1 parent 76798d5 commit 737eee7

10 files changed

Lines changed: 39 additions & 32 deletions

src/Security/Authorizator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010

1111
/**
12-
* Authorizator checks if a given role has authorization
13-
* to access a given resource.
12+
* Checks whether a given role has access to a given resource.
1413
*/
1514
interface Authorizator
1615
{

src/Security/Identity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function getRoles(): array
7272

7373

7474
/**
75-
* Returns a user data.
75+
* Returns user data.
7676
*/
7777
public function getData(): array
7878
{

src/Security/IdentityHandler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99

1010

1111
/**
12-
* Adjusts identity from/to storage.
12+
* Serializes and restores identity to/from persistent storage.
1313
*/
1414
interface IdentityHandler
1515
{
16+
/**
17+
* Called before identity is written to storage. Typically replaces the full identity with a lightweight token.
18+
*/
1619
function sleepIdentity(IIdentity $identity): IIdentity;
1720

21+
/**
22+
* Called after identity is read from storage. Typically refreshes roles or validates the token. Returns null to force logout.
23+
*/
1824
function wakeupIdentity(IIdentity $identity): ?IIdentity;
1925
}

src/Security/Passwords.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313

1414
/**
15-
* Password Hashing.
15+
* Password hashing and verification.
1616
*/
1717
class Passwords
1818
{
1919
/**
20-
* Chooses which secure algorithm is used for hashing and how to configure it.
20+
* Configures the hashing algorithm and its options.
2121
* @see https://php.net/manual/en/password.constants.php
2222
*/
2323
public function __construct(
@@ -28,7 +28,7 @@ public function __construct(
2828

2929

3030
/**
31-
* Computes password´s hash. The result contains the algorithm ID and its settings, cryptographical salt and the hash itself.
31+
* Computes a password hash containing the algorithm ID, settings, salt, and the hash itself.
3232
*/
3333
public function hash(
3434
#[\SensitiveParameter]
@@ -49,7 +49,7 @@ public function hash(
4949

5050

5151
/**
52-
* Finds out, whether the given password matches the given hash.
52+
* Checks whether the password matches the given hash.
5353
*/
5454
public function verify(
5555
#[\SensitiveParameter]
@@ -62,7 +62,7 @@ public function verify(
6262

6363

6464
/**
65-
* Finds out if the hash matches the options given in constructor.
65+
* Checks whether the hash needs to be rehashed with the current algorithm and options.
6666
*/
6767
public function needsRehash(string $hash): bool
6868
{

src/Security/Permission.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function addRole(string $role, string|array|null $parents = null): static
8080

8181

8282
/**
83-
* Returns true if the Role exists in the list.
83+
* Checks whether the Role exists in the list.
8484
*/
8585
public function hasRole(string $role): bool
8686
{
@@ -213,7 +213,7 @@ public function removeAllRoles(): static
213213

214214

215215
/**
216-
* Adds a Resource having an identifier unique to the list.
216+
* Adds a Resource to the list.
217217
*
218218
* @throws Nette\InvalidArgumentException
219219
* @throws Nette\InvalidStateException
@@ -241,7 +241,7 @@ public function addResource(string $resource, ?string $parent = null): static
241241

242242

243243
/**
244-
* Returns true if the Resource exists in the list.
244+
* Checks whether the Resource exists in the list.
245245
*/
246246
public function hasResource(string $resource): bool
247247
{
@@ -603,7 +603,7 @@ public function isAllowed(
603603

604604

605605
/**
606-
* Returns real currently queried Role. Use by assertion.
606+
* Returns the role currently being queried. Used by assertion callbacks.
607607
*/
608608
public function getQueriedRole(): string|Role|null
609609
{
@@ -612,7 +612,7 @@ public function getQueriedRole(): string|Role|null
612612

613613

614614
/**
615-
* Returns real currently queried Resource. Use by assertion.
615+
* Returns the resource currently being queried. Used by assertion callbacks.
616616
*/
617617
public function getQueriedResource(): string|Resource|null
618618
{

src/Security/Resource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
/**
12-
* Represents resource, an object to which access is controlled.
12+
* Represents a resource to which access is controlled.
1313
*/
1414
interface Resource
1515
{

src/Security/Role.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
/**
12-
* Represents role, an object that may request access to an IResource.
12+
* Represents a role that can be granted access to resources.
1313
*/
1414
interface Role
1515
{

src/Security/SimpleAuthenticator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public function __construct(
2828

2929

3030
/**
31-
* Performs an authentication against e.g. database.
32-
* and returns IIdentity on success or throws AuthenticationException
31+
* Authenticates against the in-memory list of users (case-insensitive username).
3332
* @throws AuthenticationException
3433
*/
3534
public function authenticate(

src/Security/User.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ final public function getStorage(): UserStorage
7979

8080

8181
/**
82-
* Conducts the authentication process. Parameters are optional.
83-
* @param string|IIdentity $username name or Identity
82+
* Authenticates the user. Accepts username and password, or an IIdentity directly.
83+
* @param string|IIdentity $username username or identity
8484
* @throws AuthenticationException if authentication was not successful
8585
*/
8686
public function login(
@@ -128,7 +128,7 @@ final public function logout(bool $clearIdentity = false): void
128128

129129

130130
/**
131-
* Is this user authenticated?
131+
* Checks whether the user is authenticated.
132132
*/
133133
final public function isLoggedIn(): bool
134134
{
@@ -141,7 +141,7 @@ final public function isLoggedIn(): bool
141141

142142

143143
/**
144-
* Returns current user identity, if any.
144+
* Returns the current user identity, or null if not authenticated.
145145
*/
146146
final public function getIdentity(): ?IIdentity
147147
{
@@ -178,6 +178,9 @@ public function getId(): string|int|null
178178
}
179179

180180

181+
/**
182+
* Discards cached authentication state, forcing a reload from storage on next access.
183+
*/
181184
final public function refreshStorage(): void
182185
{
183186
$this->identity = $this->authenticated = $this->logoutReason = null;
@@ -208,7 +211,7 @@ final public function getAuthenticator(): IAuthenticator
208211

209212

210213
/**
211-
* Returns authentication handler.
214+
* Returns authentication handler, or null if none is set.
212215
*/
213216
final public function getAuthenticatorIfExists(): ?IAuthenticator
214217
{
@@ -234,7 +237,7 @@ public function setExpiration(?string $expire, bool $clearIdentity = false): sta
234237

235238

236239
/**
237-
* Why was user logged out? Returns LOGOUT_MANUAL or LOGOUT_INACTIVITY.
240+
* Returns the logout reason: LogoutManual or LogoutInactivity, or null if not applicable.
238241
*/
239242
final public function getLogoutReason(): ?int
240243
{
@@ -246,7 +249,7 @@ final public function getLogoutReason(): ?int
246249

247250

248251
/**
249-
* Returns a list of effective roles that a user has been granted.
252+
* Returns effective roles of the user. Unauthenticated users get the guest role.
250253
*/
251254
public function getRoles(): array
252255
{
@@ -260,7 +263,7 @@ public function getRoles(): array
260263

261264

262265
/**
263-
* Is a user in the specified effective role?
266+
* Checks whether the user has the specified effective role.
264267
*/
265268
final public function isInRole(string $role): bool
266269
{
@@ -275,8 +278,8 @@ final public function isInRole(string $role): bool
275278

276279

277280
/**
278-
* Has a user effective access to the Resource?
279-
* If $resource is null, then the query applies to all resources.
281+
* Checks whether the user has access to the given resource and privilege.
282+
* Null means all resources or all privileges.
280283
*/
281284
public function isAllowed(mixed $resource = Authorizator::All, mixed $privilege = Authorizator::All): bool
282285
{
@@ -314,7 +317,7 @@ final public function getAuthorizator(): Authorizator
314317

315318

316319
/**
317-
* Returns current authorization handler.
320+
* Returns authorization handler, or null if none is set.
318321
*/
319322
final public function getAuthorizatorIfExists(): ?Authorizator
320323
{

src/Security/UserStorage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
/**
12-
* Interface for persistent storage for user object data.
12+
* Persistent storage for user authentication state and identity.
1313
*/
1414
interface UserStorage
1515
{
@@ -20,12 +20,12 @@ interface UserStorage
2020
public const LOGOUT_INACTIVITY = 2;
2121

2222
/**
23-
* Sets the authenticated state of user.
23+
* Saves authenticated identity to storage.
2424
*/
2525
function saveAuthentication(IIdentity $identity): void;
2626

2727
/**
28-
* Removed authenticated state of user.
28+
* Removes authenticated state from storage.
2929
*/
3030
function clearAuthentication(bool $clearIdentity): void;
3131

0 commit comments

Comments
 (0)