Skip to content
This repository was archived by the owner on Feb 6, 2021. It is now read-only.

Commit 63a3d7a

Browse files
authored
Merge pull request #12 from basz/laminas-commons-migration
Laminas commons migration
2 parents 3bd3fdb + e7d086d commit 63a3d7a

File tree

74 files changed

+457
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+457
-444
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# CHANGELOG
22

3-
For changelog, please refer to the [releases](https://github.com/ZF-Commons/ZfcRbac/releases) page.
3+
For changelog, please refer to the [releases](https://github.com/Laminas-Commons/LmcRbac/releases) page.

README.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
# ZfcRbac
1+
# LmcRbac
22

3-
[![Develop Branch Build Status](https://travis-ci.org/ZF-Commons/zfc-rbac.svg?branch=develop)](http://travis-ci.org/ZF-Commons/zfc-rbac)
4-
[![Coverage Status](https://coveralls.io/repos/github/ZF-Commons/zfc-rbac/badge.svg?branch=develop)](https://coveralls.io/github/ZF-Commons/zfc-rbac?branch=develop)
5-
[![Latest Stable Version](https://poser.pugx.org/zf-commons/zfc-rbac/v/stable)](https://packagist.org/packages/zf-commons/zfc-rbac)
6-
[![Total Downloads](https://poser.pugx.org/zf-commons/zfc-rbac/downloads)](https://packagist.org/packages/zf-commons/zfc-rbac)
7-
[![Latest Unstable Version](https://poser.pugx.org/zf-commons/zfc-rbac/v/unstable)](https://packagist.org/packages/zf-commons/zfc-rbac)
8-
[![License](https://poser.pugx.org/zf-commons/zfc-rbac/license)](https://packagist.org/packages/zf-commons/zfc-rbac)
9-
[![Join the chat at https://gitter.im/ZFCommons/zfc-rbac](https://badges.gitter.im/ZFCommons/zfc-rbac.svg)](https://gitter.im/ZFCommons/zfc-rbac?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3+
[![Version](https://poser.pugx.org/laminas-commons/lmc-rbac/version)](//packagist.org/packages/laminas-commons/lmc-rbac)
4+
[![Total Downloads](https://poser.pugx.org/laminas-commons/lmc-rbac/downloads)](//packagist.org/packages/laminas-commons/lmc-rbac)
5+
[![License](https://poser.pugx.org/laminas-commons/lmc-rbac/license)](//packagist.org/packages/laminas-commons/lmc-rbac)
6+
[![Master Branch Build Status](https://travis-ci.org/Laminas-Commons/LmcRbac.svg?branch=master)](http://travis-ci.org/Laminas-Commons/LmcRbac)
7+
[![Gitter](https://badges.gitter.im/LaminasCommons/community.svg)](https://gitter.im/LaminasCommons/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
8+
[![Coverage Status](https://coveralls.io/repos/github/Laminas-Commons/LmcRbac/badge.svg?branch=master)](https://coveralls.io/github/Laminas-Commons/LmcRbac?branch=master)
9+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Laminas-Commons/LmcRbac/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Laminas-Commons/LmcRbac/?branch=master)
1010

11-
ZfcRbac is an access control library based on the RBAC permission model.
11+
Role-based access control module to provide additional features on top of Zend\Permissions\Rbac
1212

13-
**Work In Progress**; *you are looking at the next version, for stable visit the master branch.*
13+
Based on [ZF-Commons/zfc-rbac](https://github.com/ZF-Commons/zfc-rbac) v3.x. If you are looking for the Laminas version
14+
of zfc-rbac v2, please use [Laminas-Commons/LmcRbacMvc](https://github.com/Laminas-Commons/LmcRbacMvc).
1415

15-
## Requirements
16+
**Work In Progress**
1617

17-
- PHP 7.1 or higher
18+
## Requirements
1819

19-
> If you are looking for older version of ZfcRbac, please refer to the 2.x branch.
20-
> If you are using ZfcRbac 2.0, please upgrade to 3.0.
20+
- PHP 7.2 or higher
2121

2222
## Optional
2323

2424
- [DoctrineModule](https://github.com/doctrine/DoctrineModule): if you want to use some built-in role and permission providers.
25-
- [ZendDeveloperTools](https://github.com/zendframework/ZendDeveloperTools): if you want to have useful stats added to
25+
- [Laminas\DeveloperTools](https://github.com/zendframework/Laminas\DeveloperTools): if you want to have useful stats added to
2626
the Zend Developer toolbar.
2727

2828
## Upgrade
2929

30-
You can find an [upgrade guide](UPGRADE.md) to quickly upgrade your application from major versions of ZfcRbac.
30+
You can find an [upgrade guide](UPGRADE.md) to quickly upgrade your application from major versions of LmcRbac.
3131

3232
## Installation
3333

34-
ZfcRbac only officially supports installation through Composer. For Composer documentation, please refer to
34+
LmcRbac only officially supports installation through Composer. For Composer documentation, please refer to
3535
[getcomposer.org](http://getcomposer.org/).
3636

3737
Install the module:
3838

3939
```sh
40-
$ php composer.phar require zf-commons/zfc-rbac:^3.0
40+
$ php composer.phar require laminas-commons/lmc-rbac:^1.0
4141
```
4242

43-
Enable the module by adding `ZfcRbac` key to your `application.config.php` file. Customize the module by copy-pasting
44-
the `zfc_rbac.global.php.dist` file to your `config/autoload` folder.
43+
Enable the module by adding `LmcRbac` key to your `application.config.php` file. Customize the module by copy-pasting
44+
the `lmc_rbac.global.php.dist` file to your `config/autoload` folder.
4545

4646
## Documentation
4747

4848
The official documentation is available in the [/docs](docs/) folder.
4949

5050
You can also find some Doctrine entities in the [/data](data/) folder that will help you to more quickly take advantage
51-
of ZfcRbac.
51+
of LmcRbac.
5252

5353
## Support
5454

55-
- File issues at https://github.com/ZF-Commons/zfc-rbac/issues.
56-
- Ask questions in the [zf-common gitter](https://gitter.im/ZFCommons/zfc-rbac) chat.
55+
- File issues at https://github.com/Laminas-Commons/LmcRbac/issues.
56+
- Ask questions in the [LaminasCommons gitter](https://gitter.im/LaminasCommons/community) chat.

UPGRADE.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
# Upgrade guide
22

3+
## From ZfcRbac v3 to LmcRbac v1
4+
5+
The ZF-Commons orgnisation has been moved to Laminas-Commons and ZfcRbac has been split into two repositories.
6+
7+
- [LmcRbacMvc](https://github.com/Laminas-Commons/LmcRbacMvc) contains the old version 2 of ZfcRbac.
8+
- LmcRbac contains the version 3 of ZfcRbac, which was only released as v3.alpha.1.
9+
10+
To upgrade
11+
12+
- Uninstall `zf-commons/zfc-rbac:3.0.0-alpha.1`.
13+
- Install `laminas-commons/lmc-rbac:^1.0`
14+
- Change `zfc-rbac.global.php` to `lmc-rbac.global.php` and update the key `zfc_rbac` to `lmc_rbac`.
15+
- Review your code for usages of the `ZfcRbac/*` namespace to `LmcRbac/*` namespace.
16+
317
## From v2.x to v3
418

519
- ZfcRbac is no longer a ZF2 module. Instead, it fully embraces middlewares and can be used for any middleware
6-
library like Zend\Expressive. As a consequence, its scope has been dramatically reduced and now only provide
20+
library like Mezzio. As a consequence, its scope has been dramatically reduced and now only provide
721
the base logic for authorization.
822

923
## From v2.2 to v2.3

composer.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "zf-commons/zfc-rbac",
3-
"description": "Zend Framework 2 Module that provides a layer of features of Zend\\Permissions\\Rbac",
2+
"name": "laminas-commons/lmc-rbac",
3+
"description": "Laminas Module that provides a layer of features of Laminas\\Permissions\\Rbac",
44
"type": "library",
55
"license": "MIT",
66
"keywords": [
77
"module",
8-
"zf2",
8+
"laminas",
99
"rbac",
1010
"permissions"
1111
],
@@ -36,8 +36,8 @@
3636
],
3737
"require": {
3838
"php": "^7.2",
39-
"zendframework/zend-servicemanager": "^3.3",
40-
"zendframework/zend-stdlib": "^3.1"
39+
"laminas/laminas-servicemanager": "^3.3",
40+
"laminas/laminas-stdlib": "^3.1"
4141
},
4242
"require-dev": {
4343
"malukenho/docheader": "^0.1.7",
@@ -49,22 +49,21 @@
4949
},
5050
"autoload": {
5151
"psr-4": {
52-
"ZfcRbac\\": "src/"
52+
"LmcRbac\\": "src/"
5353
}
5454
},
5555
"autoload-dev": {
5656
"psr-4": {
57-
"ZfcRbacTest\\": "test/"
57+
"LmcRbacTest\\": "test/"
5858
}
5959
},
6060
"extra": {
6161
"branch-alias": {
62-
"dev-master": "2.4-dev",
63-
"dev-develop": "3.0-dev"
62+
"dev-master": "1.1-dev"
6463
},
65-
"zf": {
66-
"component": "ZfcRbac",
67-
"config-provider": "ZfcRbac\\ConfigProvider"
64+
"laminas": {
65+
"component": "LmcRbac",
66+
"config-provider": "LmcRbac\\ConfigProvider"
6867
}
6968
},
7069
"scripts": {

config/config.global.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
return [
26-
'zfc_rbac' => [
26+
'lmc_rbac' => [
2727

2828
/**
2929
* Set the guest role
@@ -38,7 +38,7 @@
3838
* It must be an array that contains configuration for the role provider. The provider config
3939
* must follow the following format:
4040
*
41-
* 'ZfcRbac\Role\InMemoryRoleProvider' => [
41+
* 'LmcRbac\Role\InMemoryRoleProvider' => [
4242
* 'role1' => [
4343
* 'children' => ['children1', 'children2'], // OPTIONAL
4444
* 'permissions' => ['edit', 'read'] // OPTIONAL

data/FlatRole.php.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Doctrine\Common\Collections\ArrayCollection;
2020
use Doctrine\ORM\Mapping as ORM;
2121
use Rbac\Role\RoleInterface;
22-
use ZfcRbac\Permission\PermissionInterface;
22+
use LmcRbac\Permission\PermissionInterface;
2323

2424
/**
2525
* @ORM\Entity

data/HierarchicalRole.php.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Doctrine\Common\Collections\ArrayCollection;
2020
use Doctrine\ORM\Mapping as ORM;
2121
use Rbac\Role\HierarchicalRoleInterface;
22-
use ZfcRbac\Permission\PermissionInterface;
22+
use LmcRbac\Permission\PermissionInterface;
2323

2424
/**
2525
* @ORM\Entity

data/Permission.php.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
use Doctrine\ORM\Mapping as ORM;
20-
use ZfcRbac\Permission\PermissionInterface;
20+
use LmcRbac\Permission\PermissionInterface;
2121

2222
/**
2323
* @ORM\Entity

data/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
These files are only provided as-in, and are not part of ZfcRbac. They provide you some basic Doctrine ORM
1+
These files are only provided as-in, and are not part of LmcRbac. They provide you some basic Doctrine ORM
22
entities that you can use as a starting point.
33

44
## Flat role or hierarchical role?

docs/01. Introduction.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Introduction
22

3-
Welcome to the official documentation of ZfcRbac!
3+
Welcome to the official documentation of LmcRbac!
44

55
In this part, the following questions will be answered:
66

77
* Why should I use an authorization module?
88
* What is the Rbac model?
9-
* How can I integrate ZfcRbac into my application?
9+
* How can I integrate LmcRbac into my application?
1010

1111
## Why should I use an authorization module?
1212

@@ -28,17 +28,17 @@ The basic idea of Rbac is to use roles and permissions:
2828
* **Roles** request access to **Permissions**
2929
* **Permissions** are granted to **Roles**
3030

31-
By default, ZfcRbac can be used for two kinds of Rbac model:
31+
By default, LmcRbac can be used for two kinds of Rbac model:
3232

3333
* Flat RBAC model: in this model, roles cannot have children. This is ideal for smaller application, as it is easier
3434
to understand, and the database design is simpler (no need for a join table).
3535
* Hierarchical RBAC model: in this model, roles can have children roles. When evaluating if a given role has a
3636
permission, this model also checks recursively if any of its child roles also have the permission.
3737

3838

39-
## How can I integrate ZfcRbac into my application?
39+
## How can I integrate LmcRbac into my application?
4040

41-
ZfcRbac offers multiple ways to protect your application:
41+
LmcRbac offers multiple ways to protect your application:
4242

4343
* Using **Guards**: those classes act as "firewalls" that block access to routes and/or controllers. Guards are usually
4444
configured using PHP arrays, and are executed early in the MVC dispatch process. Typically this happens right after

docs/02. Quick Start.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ the README file.
1111

1212
## Specifying an identity provider
1313

14-
By default, ZfcRbac internally uses the `Zend\Authentication\AuthenticationService` service key to retrieve the user (logged or
14+
By default, LmcRbac internally uses the `Laminas\Authentication\AuthenticationService` service key to retrieve the user (logged or
1515
not). Therefore, you must implement and register this service in your application by adding those lines in your `module.config.php` file:
1616

1717
```php
1818
return [
1919
'service_manager' => [
2020
'factories' => [
21-
'Zend\Authentication\AuthenticationService' => function($sm) {
21+
'Laminas\Authentication\AuthenticationService' => function($sm) {
2222
// Create your authentication service!
2323
}
2424
]
2525
]
2626
];
2727
```
28-
The identity given by `Zend\Authentication\AuthenticationService` must implement `ZfcRbac\Identity\IdentityInterface`. Note that the default identity provided with ZF2 does not implement this interface, neither does the ZfcUser suite.
28+
The identity given by `Laminas\Authentication\AuthenticationService` must implement `LmcRbac\Identity\IdentityInterface`. Note that the default identity provided with ZF2 does not implement this interface, neither does the ZfcUser suite.
2929

30-
ZfcRbac is flexible enough to use something else than the built-in `AuthenticationService`, by specifying custom
30+
LmcRbac is flexible enough to use something else than the built-in `AuthenticationService`, by specifying custom
3131
identity providers. For more information, refer [to this section](/docs/03. Role providers.md#identity-providers).
3232

3333
## Adding a guard
@@ -37,32 +37,32 @@ grants access to any route that begins with `admin` (or is exactly `admin`) to t
3737

3838
```php
3939
return [
40-
'zfc_rbac' => [
40+
'lmc_rbac' => [
4141
'guards' => [
42-
'ZfcRbac\Guard\RouteGuard' => [
42+
'LmcRbac\Guard\RouteGuard' => [
4343
'admin*' => ['admin']
4444
]
4545
]
4646
]
4747
];
4848
```
4949

50-
ZfcRbac have several built-in guards, and you can also register your own guards. For more information, refer
50+
LmcRbac have several built-in guards, and you can also register your own guards. For more information, refer
5151
[to this section](/docs/04. Guards.md#built-in-guards).
5252

5353
## Adding a role provider
5454

55-
RBAC model is based on roles. Therefore, for ZfcRbac to work properly, it must be aware of all the roles that are
55+
RBAC model is based on roles. Therefore, for LmcRbac to work properly, it must be aware of all the roles that are
5656
used inside your application.
5757

5858
This configuration creates an *admin* role that has a children role called *member*. The *admin* role automatically
5959
inherits the *member* permissions.
6060

6161
```php
6262
return [
63-
'zfc_rbac' => [
63+
'lmc_rbac' => [
6464
'role_provider' => [
65-
\ZfcRbac\Role\InMemoryRoleProvider::class => [
65+
\LmcRbac\Role\InMemoryRoleProvider::class => [
6666
'admin' => [
6767
'children' => ['member'],
6868
'permissions' => ['delete']
@@ -79,15 +79,15 @@ return [
7979
In this example, the *admin* role have two permissions: `delete` and `edit` (because it inherits the permissions from
8080
its child), while the *member* role only has the permission `edit`.
8181

82-
ZfcRbac have several built-in role providers, and you can also register your own role providers. For more information,
82+
LmcRbac have several built-in role providers, and you can also register your own role providers. For more information,
8383
refer [to this section](/docs/03. Role providers.md#built-in-role-providers).
8484

8585
## Registering a strategy
8686

87-
When a guard blocks access to a route/controller, or if you throw the `ZfcRbac\Exception\UnauthorizedException`
88-
exception in your service, ZfcRbac automatically performs some logic for you depending on the view strategy used.
87+
When a guard blocks access to a route/controller, or if you throw the `LmcRbac\Exception\UnauthorizedException`
88+
exception in your service, LmcRbac automatically performs some logic for you depending on the view strategy used.
8989

90-
For instance, if you want ZfcRbac to automatically redirect all unauthorized requests to the "login" route, add
90+
For instance, if you want LmcRbac to automatically redirect all unauthorized requests to the "login" route, add
9191
the following code in the `onBootstrap` method of your `Module.php` class:
9292

9393
```php
@@ -96,28 +96,28 @@ public function onBootstrap(EventInterface $e)
9696
$t = $e->getTarget();
9797

9898
$t->getEventManager()->attach(
99-
$t->getServiceManager()->get('ZfcRbac\View\Strategy\RedirectStrategy')
99+
$t->getServiceManager()->get('LmcRbac\View\Strategy\RedirectStrategy')
100100
);
101101
}
102102
```
103103

104104
By default, `RedirectStrategy` redirects all unauthorized requests to a route named "login" when user is not connected
105105
and to a route named "home" when user is connected. This is, of course, entirely configurable.
106106

107-
> For flexibility purpose, ZfcRbac **does not** register any strategy for you by default!
107+
> For flexibility purpose, LmcRbac **does not** register any strategy for you by default!
108108
109109
For more information about built-in strategies, refer [to this section](/docs/05. Strategies.md#built-in-strategies).
110110

111111
## Using the authorization service
112112

113-
Now that ZfcRbac is properly configured, you can inject the authorization service in any class and use it to check
113+
Now that LmcRbac is properly configured, you can inject the authorization service in any class and use it to check
114114
if the current identity is granted to do something.
115115

116-
The authorization service is registered inside the service manager using the following key: `ZfcRbac\Service\AuthorizationService`.
116+
The authorization service is registered inside the service manager using the following key: `LmcRbac\Service\AuthorizationService`.
117117
Once injected, you can use it as follow:
118118

119119
```php
120-
use ZfcRbac\Exception\UnauthorizedException;
120+
use LmcRbac\Exception\UnauthorizedException;
121121

122122
public function delete()
123123
{

0 commit comments

Comments
 (0)