Skip to content

Commit d0623b2

Browse files
committed
BREAKING CHANGE: upgrade to PHP 8.0 and PHP-Casbin 4.0
1 parent 2d975d4 commit d0623b2

File tree

6 files changed

+54
-35
lines changed

6 files changed

+54
-35
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: true
2525
matrix:
26-
php: [ 7.1, 7.2, 7.3, 7.4 ]
26+
php: [ 8.0, 8.1, 8.2, 8.3 ]
2727
stability: [ prefer-lowest, prefer-stable ]
2828

2929
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
],
2020
"license": "Apache-2.0",
2121
"require": {
22-
"yiisoft/yii2": "~2.0.14",
23-
"casbin/casbin": "~3.1"
22+
"php": ">=8.0",
23+
"yiisoft/yii2": "~2.0.49",
24+
"casbin/casbin": "~4.0"
2425
},
2526
"require-dev": {
26-
"phpunit/phpunit": "~7.0|~8.0|~9.0|~10.5",
27-
"php-coveralls/php-coveralls": "^2.1",
28-
"yiisoft/yii2-app-basic": "~2.0.14"
27+
"phpunit/phpunit": "~9.0|~10.5",
28+
"php-coveralls/php-coveralls": "^2.7",
29+
"yiisoft/yii2-app-basic": "~2.0.49"
2930
},
3031
"autoload": {
3132
"psr-4": {

config/permission.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
'config_text' => '',
1515
],
1616

17+
// Yii-casbin logger.
18+
'log' => [
19+
// changes whether YiiPermission will log messages to the Logger.
20+
'enabled' => false,
21+
// Casbin Logger, Supported: \Psr\Log\LoggerInterface|string
22+
'logger' => 'log',
23+
],
24+
1725
// Yii-casbin adapter .
1826
'adapter' => \yii\permission\Adapter::class,
1927

phpunit.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
backupGlobals="false"
4+
bootstrap="tests/test.php"
5+
colors="true"
6+
processIsolation="false"
7+
stopOnFailure="false"
8+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
9+
cacheDirectory=".phpunit.cache"
10+
backupStaticProperties="false">
11+
<testsuites>
12+
<testsuite name="Application Test Suite">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
<php>
17+
<env name="DB_DATABASE" value="casbin"/>
18+
</php>
19+
<source>
20+
<include>
21+
<directory suffix=".php">./src</directory>
22+
</include>
23+
</source>
24+
</phpunit>

phpunit.xml.dist

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Permission.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use yii\base\Component;
66
use Casbin\Model\Model;
77
use Casbin\Enforcer;
8+
use Casbin\Log\Log;
9+
use Casbin\Log\Logger\DefaultLogger;
810
use yii\permission\models\CasbinRule;
911
use Yii;
1012

@@ -23,6 +25,8 @@ class Permission extends Component
2325

2426
public $config = [];
2527

28+
public $logger = null;
29+
2630
public function __construct($config = [])
2731
{
2832
$this->config = $this->mergeConfig(
@@ -38,6 +42,16 @@ public function __construct($config = [])
3842
} elseif ('text' == $this->config['model']['config_type']) {
3943
$this->model->loadModelFromText($this->config['model']['config_text']);
4044
}
45+
46+
if ($logger = $this->config['log']['logger']) {
47+
if ($logger === 'log') {
48+
$this->logger = new DefaultLogger();
49+
} else {
50+
$this->logger = new DefaultLogger(Yii::$container->get($logger));
51+
}
52+
53+
Log::setLogger($this->logger);
54+
}
4155
}
4256

4357
/**
@@ -68,7 +82,7 @@ public function enforcer($newInstance = false)
6882
{
6983
if ($newInstance || is_null($this->enforcer)) {
7084
$this->init();
71-
$this->enforcer = new Enforcer($this->model, $this->adapter);
85+
$this->enforcer = new Enforcer($this->model, $this->adapter, $this->logger, !is_null($this->logger));
7286
}
7387

7488
return $this->enforcer;

0 commit comments

Comments
 (0)