Skip to content

Commit 5362b06

Browse files
committed
解除 https://github.com/PHP-DI/PHP-DI 依赖的解决方案
1 parent 07ec75d commit 5362b06

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@ if (Permission::enforce("eve", "articles", "edit")) {
106106

107107
更多 `API` 参考 [Casbin API](https://casbin.org/docs/en/management-api)
108108

109+
## 其他
110+
111+
解除 [PHP-DI](https://github.com/PHP-DI/PHP-DI) 依赖的解决方案
112+
113+
```php
114+
if (is_null(static::$_manager)) {
115+
static::$_manager = new Enforcer($model, Container::get($config['adapter']),false);
116+
}
117+
```
118+
替换为
119+
```php
120+
if (is_null(static::$_manager)) {
121+
if ($config['adapter'] == DatabaseAdapter::class) {
122+
$_model = new RuleModel();
123+
} elseif ($config['adapter'] == LaravelDatabaseAdapter::class) {
124+
$_model = new LaravelRuleModel();
125+
}
126+
static::$_manager = new Enforcer($model, new $config['adapter']($_model), false);
127+
}
128+
```
129+
耦合太高,不建议这么搞,更多了解:https://www.workerman.net/doc/webman/di.html
130+
109131
## 感谢
110132

111133
[Casbin](https://github.com/php-casbin/php-casbin),你可以查看全部文档在其 [官网](https://casbin.org/) 上。

0 commit comments

Comments
 (0)