-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenerateAuthPolicyCommand.php
45 lines (32 loc) · 1.5 KB
/
GenerateAuthPolicyCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Javaabu\Generators\Commands\Auth;
use Javaabu\Generators\Generators\Auth\AuthPolicyGenerator;
use Javaabu\Generators\Generators\Auth\BaseAuthGenerator;
use Javaabu\GeneratorHelpers\StringCaser;
class GenerateAuthPolicyCommand extends BaseAuthGenerateCommand
{
protected $name = 'generate:auth_policy';
protected $description = 'Generate auth model policy based on your database table schema';
protected string $generator_class = AuthPolicyGenerator::class;
protected function createOutput(string $table, array $columns, string $auth_name): void
{
$generator = $this->getGenerator($table, $columns, $auth_name);
$output = $generator->render();
if (app()->runningInConsole()) {
$this->info("Schema-based auth model policy for table \"$table\" have been generated!");
$this->info('Copy & paste these to your policy class:');
}
$this->line($output);
}
protected function createFiles(string $table, array $columns, string $auth_name, bool $force = false, string $path = ''): void
{
$path = $this->getPath(app_path('Policies'), $path);
$file_name = StringCaser::singularStudly($table) . 'Policy.php';
$file_path = $this->getFullFilePath($path, $file_name);
$generator = $this->getGenerator($table, $columns, $auth_name);
$output = $generator->render();
if ($this->putContent($file_path, $output, $force)) {
$this->info("$file_name created!");
}
}
}