Skip to content

Commit 6cadf83

Browse files
committed
removed I prefixes from IAuthenticator, IAuthorizator, IResource, IRole, IUserStorage
1 parent 023bf33 commit 6cadf83

File tree

13 files changed

+101
-43
lines changed

13 files changed

+101
-43
lines changed

src/Bridges/SecurityDI/SecurityExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function loadConfiguration()
5858
->setFactory(Nette\Security\Passwords::class);
5959

6060
$builder->addDefinition($this->prefix('userStorage'))
61-
->setType(Nette\Security\IUserStorage::class)
61+
->setType(Nette\Security\UserStorage::class)
6262
->setFactory(Nette\Http\UserStorage::class);
6363

6464
$user = $builder->addDefinition($this->prefix('user'))
@@ -74,7 +74,7 @@ public function loadConfiguration()
7474
}
7575

7676
$builder->addDefinition($this->prefix('authenticator'))
77-
->setType(Nette\Security\IAuthenticator::class)
77+
->setType(Nette\Security\Authenticator::class)
7878
->setFactory(Nette\Security\SimpleAuthenticator::class, [$usersList, $usersRoles, $usersData]);
7979

8080
if ($this->name === 'security') {
@@ -84,7 +84,7 @@ public function loadConfiguration()
8484

8585
if ($config->roles || $config->resources) {
8686
$authorizator = $builder->addDefinition($this->prefix('authorizator'))
87-
->setType(Nette\Security\IAuthorizator::class)
87+
->setType(Nette\Security\Authorizator::class)
8888
->setFactory(Nette\Security\Permission::class);
8989

9090
foreach ($config->roles as $role => $parents) {

src/Security/IAuthenticator.php renamed to src/Security/Authenticator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Performs authentication.
1515
*/
16-
interface IAuthenticator
16+
interface Authenticator
1717
{
1818
/** Credential key */
1919
public const
@@ -34,3 +34,6 @@ interface IAuthenticator
3434
*/
3535
function authenticate(array $credentials): IIdentity;
3636
}
37+
38+
39+
interface_exists(IAuthenticator::class);

src/Security/IAuthorizator.php renamed to src/Security/Authorizator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Authorizator checks if a given role has authorization
1515
* to access a given resource.
1616
*/
17-
interface IAuthorizator
17+
interface Authorizator
1818
{
1919
/** Set type: all */
2020
public const ALL = null;
@@ -33,3 +33,6 @@ interface IAuthorizator
3333
*/
3434
function isAllowed($role, $resource, $privilege): bool;
3535
}
36+
37+
38+
interface_exists(IAuthorizator::class);

src/Security/Permission.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @copyright Copyright (c) 2005, 2007 Zend Technologies USA Inc.
2121
*/
22-
class Permission implements IAuthorizator
22+
class Permission implements Authorizator
2323
{
2424
use Nette\SmartObject;
2525

@@ -565,24 +565,24 @@ protected function setRule(bool $toAdd, bool $type, $roles, $resources, $privile
565565
* and its respective parents are checked similarly before the lower-priority parents of
566566
* the Role are checked.
567567
*
568-
* @param string|IRole|null $role
569-
* @param string|IResource|null $resource
568+
* @param string|Role|null $role
569+
* @param string|Resource|null $resource
570570
* @param string|null $privilege
571571
* @throws Nette\InvalidStateException
572572
*/
573573
public function isAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL): bool
574574
{
575575
$this->queriedRole = $role;
576576
if ($role !== self::ALL) {
577-
if ($role instanceof IRole) {
577+
if ($role instanceof Role) {
578578
$role = $role->getRoleId();
579579
}
580580
$this->checkRole($role);
581581
}
582582

583583
$this->queriedResource = $resource;
584584
if ($resource !== self::ALL) {
585-
if ($resource instanceof IResource) {
585+
if ($resource instanceof Resource) {
586586
$resource = $resource->getResourceId();
587587
}
588588
$this->checkResource($resource);

src/Security/IResource.php renamed to src/Security/Resource.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
/**
1414
* Represents resource, an object to which access is controlled.
1515
*/
16-
interface IResource
16+
interface Resource
1717
{
1818
/**
1919
* Returns a string identifier of the Resource.
2020
*/
2121
function getResourceId(): string;
2222
}
23+
24+
25+
interface_exists(IResource::class);

src/Security/IRole.php renamed to src/Security/Role.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
/**
1414
* Represents role, an object that may request access to an IResource.
1515
*/
16-
interface IRole
16+
interface Role
1717
{
1818
/**
1919
* Returns a string identifier of the Role.
2020
*/
2121
function getRoleId(): string;
2222
}
23+
24+
25+
interface_exists(IRole::class);

src/Security/SimpleAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414

1515
/**
16-
* Trivial implementation of IAuthenticator.
16+
* Trivial implementation of Authenticator.
1717
*/
18-
class SimpleAuthenticator implements IAuthenticator
18+
class SimpleAuthenticator implements Authenticator
1919
{
2020
use Nette\SmartObject;
2121

src/Security/User.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
* @property-read mixed $id
2121
* @property-read array $roles
2222
* @property-read int $logoutReason
23-
* @property IAuthenticator $authenticator
24-
* @property IAuthorizator $authorizator
23+
* @property Authenticator $authenticator
24+
* @property Authorizator $authorizator
2525
*/
2626
class User
2727
{
2828
use Nette\SmartObject;
2929

3030
/** @deprecated */
3131
public const
32-
MANUAL = IUserStorage::MANUAL,
33-
INACTIVITY = IUserStorage::INACTIVITY;
32+
MANUAL = UserStorage::MANUAL,
33+
INACTIVITY = UserStorage::INACTIVITY;
3434

3535
/** @var string default role for unauthenticated user */
3636
public $guestRole = 'guest';
@@ -44,13 +44,13 @@ class User
4444
/** @var callable[] function (User $sender): void; Occurs when the user is logged out */
4545
public $onLoggedOut;
4646

47-
/** @var IUserStorage Session storage for current user */
47+
/** @var UserStorage Session storage for current user */
4848
private $storage;
4949

50-
/** @var IAuthenticator|null */
50+
/** @var Authenticator|null */
5151
private $authenticator;
5252

53-
/** @var IAuthorizator|null */
53+
/** @var Authorizator|null */
5454
private $authorizator;
5555

5656
/** @var IIdentity|false|null false means undefined */
@@ -61,17 +61,17 @@ class User
6161

6262

6363
public function __construct(
64-
IUserStorage $storage,
65-
IAuthenticator $authenticator = null,
66-
IAuthorizator $authorizator = null
64+
UserStorage $storage,
65+
Authenticator $authenticator = null,
66+
Authorizator $authorizator = null
6767
) {
6868
$this->storage = $storage;
6969
$this->authenticator = $authenticator;
7070
$this->authorizator = $authorizator;
7171
}
7272

7373

74-
final public function getStorage(): IUserStorage
74+
final public function getStorage(): UserStorage
7575
{
7676
return $this->storage;
7777
}
@@ -155,7 +155,7 @@ public function getId()
155155
* Sets authentication handler.
156156
* @return static
157157
*/
158-
public function setAuthenticator(IAuthenticator $handler)
158+
public function setAuthenticator(Authenticator $handler)
159159
{
160160
$this->authenticator = $handler;
161161
return $this;
@@ -165,7 +165,7 @@ public function setAuthenticator(IAuthenticator $handler)
165165
/**
166166
* Returns authentication handler.
167167
*/
168-
final public function getAuthenticator(): ?IAuthenticator
168+
final public function getAuthenticator(): ?Authenticator
169169
{
170170
if (func_num_args()) {
171171
trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getAuthenticatorIfExists()', E_USER_DEPRECATED);
@@ -181,7 +181,7 @@ final public function getAuthenticator(): ?IAuthenticator
181181
/**
182182
* Returns authentication handler.
183183
*/
184-
final public function getAuthenticatorIfExists(): ?IAuthenticator
184+
final public function getAuthenticatorIfExists(): ?Authenticator
185185
{
186186
return $this->authenticator;
187187
}
@@ -195,14 +195,14 @@ final public function hasAuthenticator(): bool
195195

196196

197197
/**
198-
* Enables log out after inactivity (like '20 minutes'). Accepts flag IUserStorage::CLEAR_IDENTITY.
198+
* Enables log out after inactivity (like '20 minutes'). Accepts flag UserStorage::CLEAR_IDENTITY.
199199
* @param string|null $expire
200200
* @param int $flags
201201
* @return static
202202
*/
203203
public function setExpiration($expire, /*int*/$flags = 0)
204204
{
205-
$clearIdentity = $flags === IUserStorage::CLEAR_IDENTITY;
205+
$clearIdentity = $flags === UserStorage::CLEAR_IDENTITY;
206206
if ($expire !== null && !is_string($expire)) {
207207
trigger_error("Expiration should be a string like '20 minutes' etc.", E_USER_DEPRECATED);
208208
}
@@ -211,9 +211,9 @@ public function setExpiration($expire, /*int*/$flags = 0)
211211
}
212212
if (func_num_args() > 2) {
213213
$clearIdentity = $clearIdentity || func_get_arg(2);
214-
trigger_error(__METHOD__ . '() third parameter is deprecated, use flag setExpiration($time, IUserStorage::CLEAR_IDENTITY)', E_USER_DEPRECATED);
214+
trigger_error(__METHOD__ . '() third parameter is deprecated, use flag setExpiration($time, UserStorage::CLEAR_IDENTITY)', E_USER_DEPRECATED);
215215
}
216-
$this->storage->setExpiration($expire, $clearIdentity ? IUserStorage::CLEAR_IDENTITY : 0);
216+
$this->storage->setExpiration($expire, $clearIdentity ? UserStorage::CLEAR_IDENTITY : 0);
217217
return $this;
218218
}
219219

@@ -257,7 +257,7 @@ final public function isInRole(string $role): bool
257257
* Has a user effective access to the Resource?
258258
* If $resource is null, then the query applies to all resources.
259259
*/
260-
public function isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthorizator::ALL): bool
260+
public function isAllowed($resource = Authorizator::ALL, $privilege = Authorizator::ALL): bool
261261
{
262262
foreach ($this->getRoles() as $role) {
263263
if ($this->getAuthorizator()->isAllowed($role, $resource, $privilege)) {
@@ -273,7 +273,7 @@ public function isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthoriz
273273
* Sets authorization handler.
274274
* @return static
275275
*/
276-
public function setAuthorizator(IAuthorizator $handler)
276+
public function setAuthorizator(Authorizator $handler)
277277
{
278278
$this->authorizator = $handler;
279279
return $this;
@@ -283,7 +283,7 @@ public function setAuthorizator(IAuthorizator $handler)
283283
/**
284284
* Returns current authorization handler.
285285
*/
286-
final public function getAuthorizator(): ?IAuthorizator
286+
final public function getAuthorizator(): ?Authorizator
287287
{
288288
if (func_num_args()) {
289289
trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getAuthorizatorIfExists()', E_USER_DEPRECATED);
@@ -299,7 +299,7 @@ final public function getAuthorizator(): ?IAuthorizator
299299
/**
300300
* Returns current authorization handler.
301301
*/
302-
final public function getAuthorizatorIfExists(): ?IAuthorizator
302+
final public function getAuthorizatorIfExists(): ?Authorizator
303303
{
304304
return $this->authorizator;
305305
}

src/Security/IUserStorage.php renamed to src/Security/UserStorage.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
/**
1414
* Interface for persistent storage for user object data.
1515
*/
16-
interface IUserStorage
16+
interface UserStorage
1717
{
18-
/** Log-out reason {@link IUserStorage::getLogoutReason()} */
18+
/** Log-out reason {@link UserStorage::getLogoutReason()} */
1919
public const
2020
MANUAL = 0b0001,
2121
INACTIVITY = 0b0010;
@@ -46,7 +46,7 @@ function setIdentity(?IIdentity $identity);
4646
function getIdentity(): ?IIdentity;
4747

4848
/**
49-
* Enables log out from the persistent storage after inactivity (like '20 minutes'). Accepts flag IUserStorage::CLEAR_IDENTITY.
49+
* Enables log out from the persistent storage after inactivity (like '20 minutes'). Accepts flag UserStorage::CLEAR_IDENTITY.
5050
* @return static
5151
*/
5252
function setExpiration(?string $expire, int $flags = 0);
@@ -56,3 +56,6 @@ function setExpiration(?string $expire, int $flags = 0);
5656
*/
5757
function getLogoutReason(): ?int;
5858
}
59+
60+
61+
interface_exists(IUserStorage::class);

src/compatibility.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Nette\Security;
11+
12+
if (false) {
13+
/** @deprecated use Nette\Security\Authenticator */
14+
class IAuthenticator
15+
{
16+
}
17+
18+
/** @deprecated use Nette\Security\Authorizator */
19+
class IAuthorizator
20+
{
21+
}
22+
23+
/** @deprecated use Nette\Security\Resource */
24+
class IResource
25+
{
26+
}
27+
28+
/** @deprecated use Nette\Security\Role */
29+
class IRole
30+
{
31+
}
32+
33+
/** @deprecated use Nette\Security\UserStorage */
34+
class IUserStorage
35+
{
36+
}
37+
} elseif (!interface_exists(IAuthenticator::class)) {
38+
class_alias(Authenticator::class, IAuthenticator::class);
39+
class_alias(Authorizator::class, IAuthorizator::class);
40+
class_alias(Resource::class, IResource::class);
41+
class_alias(Role::class, IRole::class);
42+
class_alias(UserStorage::class, IUserStorage::class);
43+
}

0 commit comments

Comments
 (0)