Skip to content

Commit dc8fac7

Browse files
committed
removed I prefixes from IAuthorizator, IResource, IRole
1 parent e6086e2 commit dc8fac7

File tree

8 files changed

+57
-18
lines changed

8 files changed

+57
-18
lines changed

src/Bridges/SecurityDI/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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/User.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @property-read array $roles
2222
* @property-read int $logoutReason
2323
* @property IAuthenticator $authenticator
24-
* @property IAuthorizator $authorizator
24+
* @property Authorizator $authorizator
2525
*/
2626
class User
2727
{
@@ -50,7 +50,7 @@ class User
5050
/** @var IAuthenticator|null */
5151
private $authenticator;
5252

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

5656
/** @var IIdentity|null */
@@ -63,7 +63,7 @@ class User
6363
public function __construct(
6464
IUserStorage $storage,
6565
IAuthenticator $authenticator = null,
66-
IAuthorizator $authorizator = null
66+
Authorizator $authorizator = null
6767
) {
6868
$this->storage = $storage;
6969
$this->authenticator = $authenticator;
@@ -270,7 +270,7 @@ final public function isInRole(string $role): bool
270270
* Has a user effective access to the Resource?
271271
* If $resource is null, then the query applies to all resources.
272272
*/
273-
public function isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthorizator::ALL): bool
273+
public function isAllowed($resource = Authorizator::ALL, $privilege = Authorizator::ALL): bool
274274
{
275275
foreach ($this->getRoles() as $role) {
276276
if ($this->getAuthorizator()->isAllowed($role, $resource, $privilege)) {
@@ -286,7 +286,7 @@ public function isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthoriz
286286
* Sets authorization handler.
287287
* @return static
288288
*/
289-
public function setAuthorizator(IAuthorizator $handler)
289+
public function setAuthorizator(Authorizator $handler)
290290
{
291291
$this->authorizator = $handler;
292292
return $this;
@@ -296,7 +296,7 @@ public function setAuthorizator(IAuthorizator $handler)
296296
/**
297297
* Returns current authorization handler.
298298
*/
299-
final public function getAuthorizator(): ?IAuthorizator
299+
final public function getAuthorizator(): ?Authorizator
300300
{
301301
if (func_num_args()) {
302302
trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getAuthorizatorIfExists()', E_USER_DEPRECATED);
@@ -312,7 +312,7 @@ final public function getAuthorizator(): ?IAuthorizator
312312
/**
313313
* Returns current authorization handler.
314314
*/
315-
final public function getAuthorizatorIfExists(): ?IAuthorizator
315+
final public function getAuthorizatorIfExists(): ?Authorizator
316316
{
317317
return $this->authorizator;
318318
}

src/compatibility.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Authorizator */
14+
interface IAuthorizator extends Authorizator
15+
{
16+
}
17+
18+
/** @deprecated use Nette\Security\Resource */
19+
interface IResource
20+
{
21+
}
22+
23+
/** @deprecated use Nette\Security\Role */
24+
interface IRole
25+
{
26+
}
27+
} elseif (!interface_exists(IAuthorizator::class)) {
28+
class_alias(Authorizator::class, IAuthorizator::class);
29+
class_alias(Resource::class, IResource::class);
30+
class_alias(Role::class, IRole::class);
31+
}

tests/Security/User.authorization.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
declare(strict_types=1);
88

99
use Nette\Security\IAuthenticator;
10-
use Nette\Security\IAuthorizator;
1110
use Nette\Security\Identity;
1211
use Tester\Assert;
1312

@@ -39,7 +38,7 @@ class Authenticator implements IAuthenticator
3938
}
4039

4140

42-
class Authorizator implements IAuthorizator
41+
class Authorizator implements Nette\Security\Authorizator
4342
{
4443
public function isAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL): bool
4544
{

0 commit comments

Comments
 (0)