Skip to content

Commit 012fee7

Browse files
committed
removed I prefixes from IAuthenticator, IAuthorizator, IResource, IRole, IUserStorage
1 parent c213b60 commit 012fee7

File tree

14 files changed

+123
-43
lines changed

14 files changed

+123
-43
lines changed

ecs.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* Rules for Nette Coding Standard
5+
* https://github.com/nette/coding-standard
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
11+
return function (Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator): void {
12+
$containerConfigurator->import(PRESET_DIR . '/php71.php');
13+
14+
$parameters = $containerConfigurator->parameters();
15+
16+
$parameters->set('skip', [
17+
// Resource typehint
18+
PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer::class => [
19+
'src/Security/Permission.php',
20+
],
21+
]);
22+
};

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
}
@@ -162,7 +162,7 @@ final public function refreshStorage(): void
162162
* Sets authentication handler.
163163
* @return static
164164
*/
165-
public function setAuthenticator(IAuthenticator $handler)
165+
public function setAuthenticator(Authenticator $handler)
166166
{
167167
$this->authenticator = $handler;
168168
return $this;
@@ -172,7 +172,7 @@ public function setAuthenticator(IAuthenticator $handler)
172172
/**
173173
* Returns authentication handler.
174174
*/
175-
final public function getAuthenticator(): ?IAuthenticator
175+
final public function getAuthenticator(): ?Authenticator
176176
{
177177
if (func_num_args()) {
178178
trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getAuthenticatorIfExists()', E_USER_DEPRECATED);
@@ -188,7 +188,7 @@ final public function getAuthenticator(): ?IAuthenticator
188188
/**
189189
* Returns authentication handler.
190190
*/
191-
final public function getAuthenticatorIfExists(): ?IAuthenticator
191+
final public function getAuthenticatorIfExists(): ?Authenticator
192192
{
193193
return $this->authenticator;
194194
}
@@ -202,14 +202,14 @@ final public function hasAuthenticator(): bool
202202

203203

204204
/**
205-
* Enables log out after inactivity (like '20 minutes'). Accepts flag IUserStorage::CLEAR_IDENTITY.
205+
* Enables log out after inactivity (like '20 minutes'). Accepts flag UserStorage::CLEAR_IDENTITY.
206206
* @param string|null $expire
207207
* @param int $flags
208208
* @return static
209209
*/
210210
public function setExpiration($expire, /*int*/$flags = 0)
211211
{
212-
$clearIdentity = $flags === IUserStorage::CLEAR_IDENTITY;
212+
$clearIdentity = $flags === UserStorage::CLEAR_IDENTITY;
213213
if ($expire !== null && !is_string($expire)) {
214214
trigger_error("Expiration should be a string like '20 minutes' etc.", E_USER_DEPRECATED);
215215
}
@@ -218,9 +218,9 @@ public function setExpiration($expire, /*int*/$flags = 0)
218218
}
219219
if (func_num_args() > 2) {
220220
$clearIdentity = $clearIdentity || func_get_arg(2);
221-
trigger_error(__METHOD__ . '() third parameter is deprecated, use flag setExpiration($time, IUserStorage::CLEAR_IDENTITY)', E_USER_DEPRECATED);
221+
trigger_error(__METHOD__ . '() third parameter is deprecated, use flag setExpiration($time, UserStorage::CLEAR_IDENTITY)', E_USER_DEPRECATED);
222222
}
223-
$this->storage->setExpiration($expire, $clearIdentity ? IUserStorage::CLEAR_IDENTITY : 0);
223+
$this->storage->setExpiration($expire, $clearIdentity ? UserStorage::CLEAR_IDENTITY : 0);
224224
return $this;
225225
}
226226

@@ -264,7 +264,7 @@ final public function isInRole(string $role): bool
264264
* Has a user effective access to the Resource?
265265
* If $resource is null, then the query applies to all resources.
266266
*/
267-
public function isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthorizator::ALL): bool
267+
public function isAllowed($resource = Authorizator::ALL, $privilege = Authorizator::ALL): bool
268268
{
269269
foreach ($this->getRoles() as $role) {
270270
if ($this->getAuthorizator()->isAllowed($role, $resource, $privilege)) {
@@ -280,7 +280,7 @@ public function isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthoriz
280280
* Sets authorization handler.
281281
* @return static
282282
*/
283-
public function setAuthorizator(IAuthorizator $handler)
283+
public function setAuthorizator(Authorizator $handler)
284284
{
285285
$this->authorizator = $handler;
286286
return $this;
@@ -290,7 +290,7 @@ public function setAuthorizator(IAuthorizator $handler)
290290
/**
291291
* Returns current authorization handler.
292292
*/
293-
final public function getAuthorizator(): ?IAuthorizator
293+
final public function getAuthorizator(): ?Authorizator
294294
{
295295
if (func_num_args()) {
296296
trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getAuthorizatorIfExists()', E_USER_DEPRECATED);
@@ -306,7 +306,7 @@ final public function getAuthorizator(): ?IAuthorizator
306306
/**
307307
* Returns current authorization handler.
308308
*/
309-
final public function getAuthorizatorIfExists(): ?IAuthorizator
309+
final public function getAuthorizatorIfExists(): ?Authorizator
310310
{
311311
return $this->authorizator;
312312
}

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);

0 commit comments

Comments
 (0)