Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
composer require topthink/framework:${{ matrix.thinkphp }} --no-update --no-interaction
composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPStan
run: composer run phpstan -- --no-progress

- name: Run test suite
run: ./vendor/bin/phpunit

Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
"require-dev": {
"phpunit/phpunit": "~9.0",
"php-coveralls/php-coveralls": "^2.7",
"topthink/think": "~8.0"
"topthink/think": "~8.0",
"phpstan/phpstan": "^2.0"
},
"scripts": {
"phpstan": "phpstan analyse"
},
"autoload": {
"psr-4": {
Expand All @@ -50,4 +54,4 @@
]
}
}
}
}
26 changes: 26 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
parameters:
level: 5
paths:
- src
excludePaths:
- vendor
bootstrapFiles:
- vendor/topthink/framework/src/helper.php
ignoreErrors:
-
message: '#^Call to an undefined method iterable\<think\\db\\Query\>&think\\Collection\:\:hidden\(\)\.$#'
identifier: method.notFound
count: 1
path: src/adapter/DatabaseAdapter.php

-
message: '#^Call to an undefined method think\\db\\Query\:\:toArray\(\)\.$#'
identifier: method.notFound
count: 1
path: src/adapter/DatabaseAdapter.php

-
message: '#^Parameter \#1 \$model of method tauthz\\cache\\CacheHandlerContract\:\:cachePolicies\(\) expects tauthz\\model\\Rule, think\\db\\Query given\.$#'
identifier: argument.type
count: 2
path: src/adapter/DatabaseAdapter.php
7 changes: 4 additions & 3 deletions src/adapter/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Casbin\Exceptions\InvalidFilterTypeException;
use tauthz\traits\Configurable;
use think\facade\Db;
use Throwable;

/**
* DatabaseAdapter.
Expand Down Expand Up @@ -64,7 +65,7 @@ public function filterRule(array $rule): array

$i = count($rule) - 1;
for (; $i >= 0; $i--) {
if ($rule[$i] != '' && !is_null($rule[$i])) {
if ($rule[$i] != '') {
break;
}
}
Expand Down Expand Up @@ -359,8 +360,8 @@ public function loadFilteredPolicy(Model $model, $filter): void
}
$rows = $instance->select()->hidden(['id'])->toArray();
foreach ($rows as $row) {
$row = array_filter($row, fn ($value) => !is_null($value) && $value !== '');
$line = implode(', ', array_filter($row, fn ($val) => '' != $val && !is_null($val)));
$row = array_filter($row, fn($value) => $value !== '');
$line = implode(', ', array_filter($row, fn($val) => '' != $val));

$this->loadPolicyLine(trim($line), $model);
}
Expand Down
26 changes: 14 additions & 12 deletions src/command/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace tauthz\command;

use think\console\{Command, Input, Output};
use LogicException;

/**
* 发布配置文件、迁移文件指令
Expand All @@ -28,27 +29,28 @@ protected function configure()
protected function execute(Input $input, Output $output)
{
$destination = $this->app->getRootPath() . '/database/migrations/';
if(!is_dir($destination)){
if (!is_dir($destination)) {
mkdir($destination, 0755, true);
}
$source = __DIR__.'/../../database/migrations/';
$source = __DIR__ . '/../../database/migrations/';
$handle = dir($source);
while($entry=$handle->read()) {
if(($entry!=".")&&($entry!="..")){
if(is_file($source.$entry)){
copy($source.$entry, $destination.$entry);

while ($entry = $handle->read()) {
if (($entry != ".") && ($entry != "..")) {
if (is_file($source . $entry)) {
copy($source . $entry, $destination . $entry);
}
}
}

if (!file_exists(config_path().'tauthz-rbac-model.conf')) {
copy(__DIR__.'/../../config/tauthz-rbac-model.conf', config_path().'tauthz-rbac-model.conf');
if (!file_exists(config_path() . 'tauthz-rbac-model.conf')) {
copy(__DIR__ . '/../../config/tauthz-rbac-model.conf', config_path() . 'tauthz-rbac-model.conf');
}

if (!file_exists(config_path().'tauthz.php')) {
copy(__DIR__.'/../../config/tauthz.php', config_path().'tauthz.php');
if (!file_exists(config_path() . 'tauthz.php')) {
copy(__DIR__ . '/../../config/tauthz.php', config_path() . 'tauthz.php');
}

return 0;
}
}

2 changes: 1 addition & 1 deletion src/traits/Configurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait Configurable
* Gets config value by key.
*
* @param string $key
* @param string $default
* @param mixed $default
*
* @return mixed
*/
Expand Down
Loading