Skip to content

Commit 693c1cd

Browse files
author
igor-chepurnoi
committed
require php 7.1, update tests configuration
1 parent c506951 commit 693c1cd

15 files changed

+97
-83
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ cache:
1313

1414
install:
1515
- travis_retry composer self-update && composer --version
16-
- travis_retry composer global require "fxp/composer-asset-plugin:~1.3.1"
1716
- export PATH="$HOME/.composer/vendor/bin:$PATH"
1817
- travis_retry composer install --prefer-dist --no-interaction
1918

2019
script:
2120
- vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
22-
- phpunit --verbose $PHPUNIT_FLAGS
21+
- phpunit --verbose

README.md

+22-13
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ php composer.phar require --prefer-dist yii2mod/yii2-rbac "*"
2929

3030
or add
3131

32-
```json
32+
```
3333
"yii2mod/yii2-rbac": "*"
3434
```
3535

@@ -43,19 +43,17 @@ Once the extension is installed, simply modify your application configuration as
4343
return [
4444
//....
4545
'modules' => [
46-
'admin' => [
47-
'class' => 'app\modules\admin\Module',
48-
'modules' => [
49-
'rbac' => [
50-
'class' => 'yii2mod\rbac\Module',
51-
],
46+
'class' => 'app\modules\admin\Module',
47+
'modules' => [
48+
'rbac' => [
49+
'class' => 'yii2mod\rbac\Module',
5250
],
5351
],
5452
],
5553
'components' => [
5654
'authManager' => [
5755
'class' => 'yii\rbac\DbManager',
58-
'defaultRoles' => ['guest', 'user']
56+
'defaultRoles' => ['guest', 'user'],
5957
],
6058
]
6159
];
@@ -68,12 +66,23 @@ $ php yii migrate/up --migrationPath=@yii/rbac/migrations
6866
```
6967

7068
You can then access Auth manager through the following URL:
69+
70+
```
71+
http://localhost/path/to/index.php?r=rbac/
72+
http://localhost/path/to/index.php?r=rbac/route
73+
http://localhost/path/to/index.php?r=rbac/permission
74+
http://localhost/path/to/index.php?r=rbac/role
75+
http://localhost/path/to/index.php?r=rbac/assignment
76+
```
77+
78+
or if you have enabled pretty URLs, you may use the following URL:
79+
7180
```
72-
http://localhost/path/to/index.php?r=admin/rbac/
73-
http://localhost/path/to/index.php?r=admin/rbac/route
74-
http://localhost/path/to/index.php?r=admin/rbac/permission
75-
http://localhost/path/to/index.php?r=admin/rbac/role
76-
http://localhost/path/to/index.php?r=admin/rbac/assignment
81+
http://localhost/path/to/index.php/rbac
82+
http://localhost/path/to/index.php/rbac/route
83+
http://localhost/path/to/index.php/rbac/permission
84+
http://localhost/path/to/index.php/rbac/role
85+
http://localhost/path/to/index.php/rbac/assignment
7786
```
7887

7988
**Applying rules:**

base/ItemController.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ItemController extends Controller
3838
/**
3939
* @inheritdoc
4040
*/
41-
public function behaviors()
41+
public function behaviors(): array
4242
{
4343
return [
4444
'verbs' => [
@@ -83,11 +83,11 @@ public function actionIndex()
8383
/**
8484
* Displays a single AuthItem model.
8585
*
86-
* @param string $id
86+
* @param int $id
8787
*
8888
* @return mixed
8989
*/
90-
public function actionView($id)
90+
public function actionView(int $id)
9191
{
9292
$model = $this->findModel($id);
9393

@@ -120,11 +120,11 @@ public function actionCreate()
120120
*
121121
* If update is successful, the browser will be redirected to the 'view' page.
122122
*
123-
* @param string $id
123+
* @param int $id
124124
*
125125
* @return mixed
126126
*/
127-
public function actionUpdate($id)
127+
public function actionUpdate(int $id)
128128
{
129129
$model = $this->findModel($id);
130130

@@ -142,11 +142,11 @@ public function actionUpdate($id)
142142
*
143143
* If deletion is successful, the browser will be redirected to the 'index' page.
144144
*
145-
* @param string $id
145+
* @param int $id
146146
*
147147
* @return mixed
148148
*/
149-
public function actionDelete($id)
149+
public function actionDelete(int $id)
150150
{
151151
$model = $this->findModel($id);
152152
Yii::$app->getAuthManager()->remove($model->item);
@@ -158,11 +158,11 @@ public function actionDelete($id)
158158
/**
159159
* Assign items
160160
*
161-
* @param string $id
161+
* @param int $id
162162
*
163163
* @return array
164164
*/
165-
public function actionAssign($id)
165+
public function actionAssign(int $id)
166166
{
167167
$items = Yii::$app->getRequest()->post('items', []);
168168
$model = $this->findModel($id);
@@ -174,11 +174,11 @@ public function actionAssign($id)
174174
/**
175175
* Remove items
176176
*
177-
* @param string $id
177+
* @param int $id
178178
*
179179
* @return array
180180
*/
181-
public function actionRemove($id)
181+
public function actionRemove(int $id): array
182182
{
183183
$items = Yii::$app->getRequest()->post('items', []);
184184
$model = $this->findModel($id);
@@ -190,23 +190,23 @@ public function actionRemove($id)
190190
/**
191191
* @inheritdoc
192192
*/
193-
public function getViewPath()
193+
public function getViewPath(): string
194194
{
195195
return $this->module->getViewPath() . DIRECTORY_SEPARATOR . 'item';
196196
}
197197

198198
/**
199199
* @return int
200200
*/
201-
public function getType()
201+
public function getType(): int
202202
{
203203
return $this->type;
204204
}
205205

206206
/**
207207
* @return array
208208
*/
209-
public function getLabels()
209+
public function getLabels(): array
210210
{
211211
return $this->labels;
212212
}
@@ -216,13 +216,13 @@ public function getLabels()
216216
*
217217
* If the model is not found, a 404 HTTP exception will be thrown.
218218
*
219-
* @param string $id
219+
* @param int $id
220220
*
221221
* @return AuthItemModel the loaded model
222222
*
223223
* @throws NotFoundHttpException if the model cannot be found
224224
*/
225-
protected function findModel($id)
225+
protected function findModel(int $id): AuthItemModel
226226
{
227227
$auth = Yii::$app->getAuthManager();
228228
$item = $this->type === Item::TYPE_ROLE ? $auth->getRole($id) : $auth->getPermission($id);

commands/MigrateController.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
/**
1212
* Class MigrateController
1313
*
14-
* @package yii2mod\rbac\commands
15-
*
1614
* Below are some common usages of this command:
1715
*
1816
* ```
@@ -51,16 +49,17 @@ class MigrateController extends BaseMigrateController
5149
/**
5250
* @inheritdoc
5351
*/
54-
public function init()
52+
public function init(): void
5553
{
5654
$this->db = Instance::ensure($this->db, Connection::class);
55+
5756
parent::init();
5857
}
5958

6059
/**
61-
* @return array|string|Connection
60+
* @return Connection
6261
*/
63-
public function getDb()
62+
public function getDb(): Connection
6463
{
6564
return $this->db;
6665
}

composer.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
}
2323
],
2424
"require": {
25-
"php": ">=5.6",
26-
"yiisoft/yii2": "^2.0.8",
25+
"php": ">=7.1",
26+
"yiisoft/yii2": "~2.0.10",
2727
"2amigos/yii2-arrayquery-component": "*",
2828
"yiisoft/yii2-jui": "*"
2929
},
@@ -34,5 +34,11 @@
3434
"psr-4": {
3535
"yii2mod\\rbac\\": ""
3636
}
37-
}
37+
},
38+
"repositories": [
39+
{
40+
"type": "composer",
41+
"url": "https://asset-packagist.org"
42+
}
43+
]
3844
}

filters/AccessControl.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AccessControl extends \yii\filters\AccessControl
2828
/**
2929
* @inheritdoc
3030
*/
31-
public function beforeAction($action)
31+
public function beforeAction($action): bool
3232
{
3333
$controller = $action->controller;
3434
$params = ArrayHelper::getValue($this->params, $action->id, []);
@@ -50,7 +50,7 @@ public function beforeAction($action)
5050
/**
5151
* @inheritdoc
5252
*/
53-
protected function isActive($action)
53+
protected function isActive($action): bool
5454
{
5555
if ($this->isErrorPage($action) || $this->isLoginPage($action) || $this->isAllowedAction($action)) {
5656
return false;
@@ -66,7 +66,7 @@ protected function isActive($action)
6666
*
6767
* @return bool
6868
*/
69-
private function isErrorPage($action)
69+
private function isErrorPage(Action $action): bool
7070
{
7171
if ($action->getUniqueId() === Yii::$app->getErrorHandler()->errorAction) {
7272
return true;
@@ -82,7 +82,7 @@ private function isErrorPage($action)
8282
*
8383
* @return bool
8484
*/
85-
private function isLoginPage($action)
85+
private function isLoginPage(Action $action): bool
8686
{
8787
$loginUrl = trim(Url::to(Yii::$app->user->loginUrl), '/');
8888

@@ -100,7 +100,7 @@ private function isLoginPage($action)
100100
*
101101
* @return bool
102102
*/
103-
private function isAllowedAction($action)
103+
private function isAllowedAction(Action $action): bool
104104
{
105105
if ($this->owner instanceof Module) {
106106
$ownerId = $this->owner->getUniqueId();

migrations/Migration.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Migration extends Component implements MigrationInterface
3131
public function init()
3232
{
3333
$this->authManager = Instance::ensure($this->authManager, DbManager::class);
34+
3435
parent::init();
3536
}
3637

models/AssignmentModel.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function __construct(IdentityInterface $user, $config = [])
5555
*
5656
* @param array $items
5757
*
58-
* @return int number of successful grand
58+
* @return bool
5959
*/
60-
public function assign($items)
60+
public function assign(array $items): bool
6161
{
6262
foreach ($items as $name) {
6363
$item = $this->manager->getRole($name);
@@ -73,9 +73,9 @@ public function assign($items)
7373
*
7474
* @param array $items
7575
*
76-
* @return int number of successful revoke
76+
* @return bool
7777
*/
78-
public function revoke($items)
78+
public function revoke(array $items): bool
7979
{
8080
foreach ($items as $name) {
8181
$item = $this->manager->getRole($name);
@@ -91,7 +91,7 @@ public function revoke($items)
9191
*
9292
* @return array
9393
*/
94-
public function getItems()
94+
public function getItems(): array
9595
{
9696
$available = [];
9797
$assigned = [];

0 commit comments

Comments
 (0)