Skip to content

Commit 5ae9445

Browse files
committed
refactor: Change the field ptype to p_type
1 parent c78240b commit 5ae9445

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

database/migrations/2019_03_01_000000_create_rules_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function up()
1313
$connection = config('lauthz.basic.database.connection') ?: config('database.default');
1414
Schema::connection($connection)->create(config('lauthz.basic.database.rules_table'), function (Blueprint $table) {
1515
$table->increments('id');
16-
$table->string('ptype')->nullable();
16+
$table->string('p_type')->nullable();
1717
$table->string('v0')->nullable();
1818
$table->string('v1')->nullable();
1919
$table->string('v2')->nullable();

src/Adapters/DatabaseAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(Rule $eloquent)
4343
*/
4444
public function savePolicyLine(string $ptype, array $rule): void
4545
{
46-
$col['ptype'] = $ptype;
46+
$col['p_type'] = $ptype;
4747
foreach ($rule as $key => $value) {
4848
$col['v'.strval($key)] = $value;
4949
}
@@ -112,7 +112,7 @@ public function removePolicy(string $sec, string $ptype, array $rule): void
112112
{
113113
$count = 0;
114114

115-
$instance = $this->eloquent->where('ptype', $ptype);
115+
$instance = $this->eloquent->where('p_type', $ptype);
116116

117117
foreach ($rule as $key => $value) {
118118
$instance->where('v'.strval($key), $value);
@@ -138,7 +138,7 @@ public function removeFilteredPolicy(string $sec, string $ptype, int $fieldIndex
138138
{
139139
$count = 0;
140140

141-
$instance = $this->eloquent->where('ptype', $ptype);
141+
$instance = $this->eloquent->where('p_type', $ptype);
142142
foreach (range(0, 5) as $value) {
143143
if ($fieldIndex <= $value && $value < $fieldIndex + count($fieldValues)) {
144144
if ('' != $fieldValues[$value - $fieldIndex]) {

src/Models/Rule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Rule extends Model
2929
*
3030
* @var array
3131
*/
32-
protected $fillable = ['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5'];
32+
protected $fillable = ['p_type', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5'];
3333

3434
/**
3535
* Create a new Eloquent model instance.
@@ -62,7 +62,7 @@ public function __construct(array $attributes = [], $guard = '')
6262
public function getAllFromCache()
6363
{
6464
$get = function () {
65-
return $this->select('ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5')->get()->toArray();
65+
return $this->select('p_type', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5')->get()->toArray();
6666
};
6767
if (!$this->config('cache.enabled', false)) {
6868
return $get();

tests/RequestMiddlewareTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ protected function initTable()
6868
{
6969
Rule::truncate();
7070

71-
Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => '/foo', 'v2' => 'GET']);
72-
Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => '/foo/:id', 'v2' => 'GET']);
73-
Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => '/foo', 'v2' => 'POST']);
74-
Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => '/foo/:id', 'v2' => 'PUT']);
75-
Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => '/foo/:id', 'v2' => 'DELETE']);
76-
Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => '/foo1/*', 'v2' => '(GET)|(POST)']);
71+
Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => '/foo', 'v2' => 'GET']);
72+
Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => '/foo/:id', 'v2' => 'GET']);
73+
Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => '/foo', 'v2' => 'POST']);
74+
Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => '/foo/:id', 'v2' => 'PUT']);
75+
Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => '/foo/:id', 'v2' => 'DELETE']);
76+
Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => '/foo1/*', 'v2' => '(GET)|(POST)']);
7777
}
7878
}

tests/RuleCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testEnableCache()
2828
app(Rule::class)->getAllFromCache();
2929
$this->assertCount(0, DB::getQueryLog());
3030

31-
$rule = Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => 'data1', 'v2' => 'read']);
31+
$rule = Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => 'data1', 'v2' => 'read']);
3232
app(Rule::class)->getAllFromCache();
3333
$this->assertCount(2, DB::getQueryLog());
3434

@@ -48,7 +48,7 @@ public function testDisableCache()
4848
app(Rule::class)->getAllFromCache();
4949
$this->assertCount(1, DB::getQueryLog());
5050

51-
$rule = Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => 'data1', 'v2' => 'read']);
51+
$rule = Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => 'data1', 'v2' => 'read']);
5252
app(Rule::class)->getAllFromCache();
5353
$this->assertCount(3, DB::getQueryLog());
5454

tests/TestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ protected function initTable()
5353
{
5454
Rule::truncate();
5555

56-
Rule::create(['ptype' => 'p', 'v0' => 'alice', 'v1' => 'data1', 'v2' => 'read']);
57-
Rule::create(['ptype' => 'p', 'v0' => 'bob', 'v1' => 'data2', 'v2' => 'write']);
56+
Rule::create(['p_type' => 'p', 'v0' => 'alice', 'v1' => 'data1', 'v2' => 'read']);
57+
Rule::create(['p_type' => 'p', 'v0' => 'bob', 'v1' => 'data2', 'v2' => 'write']);
5858

59-
Rule::create(['ptype' => 'p', 'v0' => 'data2_admin', 'v1' => 'data2', 'v2' => 'read']);
60-
Rule::create(['ptype' => 'p', 'v0' => 'data2_admin', 'v1' => 'data2', 'v2' => 'write']);
61-
Rule::create(['ptype' => 'g', 'v0' => 'alice', 'v1' => 'data2_admin']);
59+
Rule::create(['p_type' => 'p', 'v0' => 'data2_admin', 'v1' => 'data2', 'v2' => 'read']);
60+
Rule::create(['p_type' => 'p', 'v0' => 'data2_admin', 'v1' => 'data2', 'v2' => 'write']);
61+
Rule::create(['p_type' => 'g', 'v0' => 'alice', 'v1' => 'data2_admin']);
6262
}
6363

6464
protected function runMiddleware($middleware, $request, ...$args)

0 commit comments

Comments
 (0)