style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
class GenerateSimpleRelationships extends Command
|
||||
{
|
||||
protected $signature = 'db:generate-simple-relationships';
|
||||
|
||||
protected $description = '기본 논리적 관계 문서 생성';
|
||||
|
||||
public function handle()
|
||||
@@ -29,7 +30,7 @@ private function getKnownRelationships(): array
|
||||
'user_tenants (hasMany)' => 'user_tenants.user_id → users.id',
|
||||
'user_roles (hasMany)' => 'user_roles.user_id → users.id',
|
||||
'audit_logs (hasMany)' => 'audit_logs.actor_id → users.id (생성자)',
|
||||
]
|
||||
],
|
||||
],
|
||||
'tenants' => [
|
||||
'description' => '테넌트 (회사/조직)',
|
||||
@@ -39,7 +40,7 @@ private function getKnownRelationships(): array
|
||||
'departments (hasMany)' => 'departments.tenant_id → tenants.id',
|
||||
'products (hasMany)' => 'products.tenant_id → tenants.id',
|
||||
'orders (hasMany)' => 'orders.tenant_id → tenants.id',
|
||||
]
|
||||
],
|
||||
],
|
||||
'categories' => [
|
||||
'description' => '제품 카테고리 (계층구조)',
|
||||
@@ -48,7 +49,7 @@ private function getKnownRelationships(): array
|
||||
'children (hasMany)' => 'categories.parent_id → categories.id',
|
||||
'products (hasMany)' => 'products.category_id → categories.id',
|
||||
'estimates (hasMany)' => 'estimates.model_set_id → categories.id (논리적)',
|
||||
]
|
||||
],
|
||||
],
|
||||
'products' => [
|
||||
'description' => '제품 마스터',
|
||||
@@ -57,7 +58,7 @@ private function getKnownRelationships(): array
|
||||
'tenant (belongsTo)' => 'products.tenant_id → tenants.id',
|
||||
'product_components (hasMany)' => 'product_components.parent_product_id → products.id (논리적)',
|
||||
'order_items (hasMany)' => 'order_items.product_id → products.id',
|
||||
]
|
||||
],
|
||||
],
|
||||
'departments' => [
|
||||
'description' => '부서 관리 (계층구조)',
|
||||
@@ -65,7 +66,7 @@ private function getKnownRelationships(): array
|
||||
'parent (belongsTo)' => 'departments.parent_id → departments.id (논리적)',
|
||||
'children (hasMany)' => 'departments.parent_id → departments.id (논리적)',
|
||||
'tenant (belongsTo)' => 'departments.tenant_id → tenants.id',
|
||||
]
|
||||
],
|
||||
],
|
||||
'estimates' => [
|
||||
'description' => '견적서 (스냅샷 데이터)',
|
||||
@@ -73,14 +74,14 @@ private function getKnownRelationships(): array
|
||||
'category (belongsTo)' => 'estimates.model_set_id → categories.id (논리적)',
|
||||
'tenant (belongsTo)' => 'estimates.tenant_id → tenants.id',
|
||||
'estimate_items (hasMany)' => 'estimate_items.estimate_id → estimates.id (논리적)',
|
||||
]
|
||||
],
|
||||
],
|
||||
'estimate_items' => [
|
||||
'description' => '견적 아이템',
|
||||
'relationships' => [
|
||||
'estimate (belongsTo)' => 'estimate_items.estimate_id → estimates.id (논리적)',
|
||||
'tenant (belongsTo)' => 'estimate_items.tenant_id → tenants.id',
|
||||
]
|
||||
],
|
||||
],
|
||||
'product_components' => [
|
||||
'description' => 'BOM 구성요소 (통합 참조구조)',
|
||||
@@ -88,13 +89,13 @@ private function getKnownRelationships(): array
|
||||
'parent_product (belongsTo)' => 'product_components.parent_product_id → products.id (논리적)',
|
||||
'material_or_product (polymorphic)' => 'product_components.ref_id → materials.id OR products.id (ref_type 기반)',
|
||||
'tenant (belongsTo)' => 'product_components.tenant_id → tenants.id',
|
||||
]
|
||||
],
|
||||
],
|
||||
'classifications' => [
|
||||
'description' => '분류 코드',
|
||||
'relationships' => [
|
||||
'tenant (belongsTo)' => 'classifications.tenant_id → tenants.id (논리적)',
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -145,4 +146,4 @@ private function generateDocument(array $relationships): void
|
||||
File::put(base_path('LOGICAL_RELATIONSHIPS_SIMPLE.md'), $content);
|
||||
$this->info('📄 문서 생성: LOGICAL_RELATIONSHIPS_SIMPLE.md');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
class MakeModelWithRelationships extends Command
|
||||
{
|
||||
protected $signature = 'make:model-with-docs {name} {--migration} {--controller} {--resource}';
|
||||
|
||||
protected $description = '모델 생성 후 자동으로 관계 문서 업데이트';
|
||||
|
||||
public function handle()
|
||||
@@ -17,9 +18,15 @@ public function handle()
|
||||
|
||||
// 기본 모델 생성
|
||||
$options = [];
|
||||
if ($this->option('migration')) $options['--migration'] = true;
|
||||
if ($this->option('controller')) $options['--controller'] = true;
|
||||
if ($this->option('resource')) $options['--resource'] = true;
|
||||
if ($this->option('migration')) {
|
||||
$options['--migration'] = true;
|
||||
}
|
||||
if ($this->option('controller')) {
|
||||
$options['--controller'] = true;
|
||||
}
|
||||
if ($this->option('resource')) {
|
||||
$options['--resource'] = true;
|
||||
}
|
||||
|
||||
Artisan::call('make:model', array_merge(['name' => $modelName], $options));
|
||||
$this->info("✅ 모델 생성 완료: {$modelName}");
|
||||
@@ -36,8 +43,9 @@ private function addRelationshipTemplate(string $modelName): void
|
||||
{
|
||||
$modelPath = app_path("Models/{$modelName}.php");
|
||||
|
||||
if (!File::exists($modelPath)) {
|
||||
if (! File::exists($modelPath)) {
|
||||
$this->error("모델 파일을 찾을 수 없습니다: {$modelPath}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,12 +73,12 @@ private function addRelationshipTemplate(string $modelName): void
|
||||
|
||||
// 클래스 끝 부분에 템플릿 삽입
|
||||
$content = str_replace(
|
||||
'}' . PHP_EOL,
|
||||
$template . PHP_EOL . '}' . PHP_EOL,
|
||||
'}'.PHP_EOL,
|
||||
$template.PHP_EOL.'}'.PHP_EOL,
|
||||
$content
|
||||
);
|
||||
|
||||
File::put($modelPath, $content);
|
||||
$this->info("📝 관계 템플릿 추가: {$modelName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
class PruneAuditLogs extends Command
|
||||
{
|
||||
protected $signature = 'audit:prune {--days=}';
|
||||
|
||||
protected $description = 'Delete audit logs older than given days (default: config(audit.retention_days)).';
|
||||
|
||||
public function handle(): int
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Commons\Menu;
|
||||
use Illuminate\Console\Command;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\PermissionRegistrar;
|
||||
|
||||
class SeedMenuPermissions extends Command
|
||||
{
|
||||
protected $signature = 'sam:seed-menu-perms {--tenant=} {--guard=api}';
|
||||
|
||||
protected $description = 'Create missing permissions menu:{id}.{action} for all menus';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$tenant = $this->option('tenant') ? (int)$this->option('tenant') : null;
|
||||
$guard = $this->option('guard') ?: 'api';
|
||||
$actions = config('authz.menu_actions', ['view','create','update','delete','approve']);
|
||||
$tenant = $this->option('tenant') ? (int) $this->option('tenant') : null;
|
||||
$guard = $this->option('guard') ?: 'api';
|
||||
$actions = config('authz.menu_actions', ['view', 'create', 'update', 'delete', 'approve']);
|
||||
|
||||
$menus = Menu::query()
|
||||
->when($tenant !== null, fn ($q) => $q->where('tenant_id', $tenant))
|
||||
@@ -25,13 +26,13 @@ public function handle(): int
|
||||
$count = 0;
|
||||
|
||||
foreach ($menus as $m) {
|
||||
app(PermissionRegistrar::class)->setPermissionsTeamId((int)$m->tenant_id);
|
||||
app(PermissionRegistrar::class)->setPermissionsTeamId((int) $m->tenant_id);
|
||||
|
||||
foreach ($actions as $act) {
|
||||
Permission::firstOrCreate([
|
||||
'tenant_id' => (int)$m->tenant_id,
|
||||
'tenant_id' => (int) $m->tenant_id,
|
||||
'guard_name' => $guard,
|
||||
'name' => "menu:{$m->id}.{$act}",
|
||||
'name' => "menu:{$m->id}.{$act}",
|
||||
]);
|
||||
$count++;
|
||||
}
|
||||
@@ -39,6 +40,7 @@ public function handle(): int
|
||||
|
||||
app(PermissionRegistrar::class)->forgetCachedPermissions();
|
||||
$this->info("Ensured {$count} permissions.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\TenantBootstrapper;
|
||||
use Illuminate\Console\Attributes\AsCommand;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Console\Attributes\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'tenants:bootstrap', description: 'Bootstrap menus/capability/categories/settings for tenant(s)')]
|
||||
class TenantsBootstrap extends Command
|
||||
@@ -18,7 +18,7 @@ class TenantsBootstrap extends Command
|
||||
|
||||
public function handle(TenantBootstrapper $svc): int
|
||||
{
|
||||
$recipe = (string) $this->option('recipe');
|
||||
$recipe = (string) $this->option('recipe');
|
||||
$tenantId = $this->option('tenant_id');
|
||||
|
||||
if ($this->option('all')) {
|
||||
@@ -27,11 +27,13 @@ public function handle(TenantBootstrapper $svc): int
|
||||
$ids = [(int) $tenantId];
|
||||
} else {
|
||||
$this->error('Provide --tenant_id=ID or --all');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
if (empty($ids)) {
|
||||
$this->warn('No tenant to bootstrap.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
class UpdateLogicalRelationships extends Command
|
||||
{
|
||||
protected $signature = 'db:update-relationships';
|
||||
|
||||
protected $description = '모델에서 논리적 관계를 추출하여 문서 업데이트';
|
||||
|
||||
public function handle()
|
||||
@@ -30,16 +31,20 @@ private function extractModelRelationships(): array
|
||||
$modelFiles = File::allFiles($modelPath);
|
||||
|
||||
foreach ($modelFiles as $file) {
|
||||
if ($file->getExtension() !== 'php') continue;
|
||||
if ($file->getExtension() !== 'php') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$className = $this->getClassNameFromFile($file);
|
||||
if (!$className || !class_exists($className)) continue;
|
||||
if (! $className || ! class_exists($className)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$reflection = new ReflectionClass($className);
|
||||
|
||||
// 모델이 Eloquent Model인지 확인
|
||||
if (!$reflection->isSubclassOf(\Illuminate\Database\Eloquent\Model::class)) {
|
||||
if (! $reflection->isSubclassOf(\Illuminate\Database\Eloquent\Model::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -50,15 +55,18 @@ private function extractModelRelationships(): array
|
||||
|
||||
// 테이블 이름 직접 추출
|
||||
$tableName = $this->getTableNameFromModel($className, $reflection);
|
||||
if (!$tableName) continue;
|
||||
if (! $tableName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$relationships[$tableName] = [
|
||||
'model' => $className,
|
||||
'relationships' => $this->getModelRelationshipsFromFile($file, $className)
|
||||
'relationships' => $this->getModelRelationshipsFromFile($file, $className),
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->warn("모델 분석 실패: {$className} - " . $e->getMessage());
|
||||
$this->warn("모델 분석 실패: {$className} - ".$e->getMessage());
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -73,7 +81,7 @@ private function getTableNameFromModel(string $className, ReflectionClass $refle
|
||||
$tableName = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $modelName));
|
||||
|
||||
// 복수형으로 변환 (간단한 규칙)
|
||||
if (!str_ends_with($tableName, 's')) {
|
||||
if (! str_ends_with($tableName, 's')) {
|
||||
$tableName .= 's';
|
||||
}
|
||||
|
||||
@@ -112,8 +120,9 @@ private function getModelRelationshipsFromFile($file, string $className): array
|
||||
'type' => $type,
|
||||
'related_model' => '(Polymorphic)',
|
||||
'foreign_key' => null,
|
||||
'local_key' => null
|
||||
'local_key' => null,
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -128,7 +137,7 @@ private function getModelRelationshipsFromFile($file, string $className): array
|
||||
'type' => $type,
|
||||
'related_model' => $fullyQualifiedClass,
|
||||
'foreign_key' => null,
|
||||
'local_key' => null
|
||||
'local_key' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -196,7 +205,7 @@ private function resolveClassName(string $className, array $useStatements, ?stri
|
||||
|
||||
// 같은 namespace에 있다고 가정
|
||||
if ($currentNamespace) {
|
||||
return $currentNamespace . '\\' . $className;
|
||||
return $currentNamespace.'\\'.$className;
|
||||
}
|
||||
|
||||
// 그 외의 경우 그대로 반환
|
||||
@@ -223,7 +232,7 @@ private function getModelRelationships(ReflectionClass $reflection, $model): arr
|
||||
'type' => $this->getRelationshipType($result),
|
||||
'related_model' => get_class($result->getRelated()),
|
||||
'foreign_key' => $this->getForeignKey($result),
|
||||
'local_key' => $this->getLocalKey($result)
|
||||
'local_key' => $this->getLocalKey($result),
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -243,6 +252,7 @@ private function isRelationshipMethod($result): bool
|
||||
private function getRelationshipType($relation): string
|
||||
{
|
||||
$className = get_class($relation);
|
||||
|
||||
return class_basename($className);
|
||||
}
|
||||
|
||||
@@ -264,15 +274,15 @@ private function getClassNameFromFile($file): ?string
|
||||
{
|
||||
$content = File::get($file->getRealPath());
|
||||
|
||||
if (!preg_match('/namespace\s+([^;]+);/', $content, $namespaceMatches)) {
|
||||
if (! preg_match('/namespace\s+([^;]+);/', $content, $namespaceMatches)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!preg_match('/class\s+(\w+)/', $content, $classMatches)) {
|
||||
if (! preg_match('/class\s+(\w+)/', $content, $classMatches)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $namespaceMatches[1] . '\\' . $classMatches[1];
|
||||
return $namespaceMatches[1].'\\'.$classMatches[1];
|
||||
}
|
||||
|
||||
private function updateLogicalDocument(array $relationships): void
|
||||
@@ -287,7 +297,9 @@ private function updateLogicalDocument(array $relationships): void
|
||||
$content .= "## 📊 모델별 관계 현황\n\n";
|
||||
|
||||
foreach ($relationships as $tableName => $info) {
|
||||
if (empty($info['relationships'])) continue;
|
||||
if (empty($info['relationships'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content .= "### {$tableName}\n";
|
||||
$content .= "**모델**: `{$info['model']}`\n\n";
|
||||
@@ -297,12 +309,14 @@ private function updateLogicalDocument(array $relationships): void
|
||||
// Polymorphic 관계는 특별 표시
|
||||
if ($rel['related_model'] === '(Polymorphic)') {
|
||||
$content .= "- **{$rel['method']}()**: {$rel['type']} → `(Polymorphic)`\n";
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// 관련 모델 클래스가 존재하는지 확인
|
||||
if (!class_exists($rel['related_model'])) {
|
||||
if (! class_exists($rel['related_model'])) {
|
||||
$this->warn("모델 클래스가 존재하지 않음: {$rel['related_model']}");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -315,7 +329,8 @@ private function updateLogicalDocument(array $relationships): void
|
||||
|
||||
$content .= "\n";
|
||||
} catch (\Exception $e) {
|
||||
$this->warn("관계 처리 실패: {$rel['method']} - " . $e->getMessage());
|
||||
$this->warn("관계 처리 실패: {$rel['method']} - ".$e->getMessage());
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -326,4 +341,4 @@ private function updateLogicalDocument(array $relationships): void
|
||||
File::put($documentPath, $content);
|
||||
$this->info("📄 문서 업데이트: {$documentPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Commands\GenerateSimpleRelationships;
|
||||
use App\Console\Commands\MakeModelWithRelationships;
|
||||
use App\Console\Commands\PruneAuditLogs;
|
||||
use App\Console\Commands\UpdateLogicalRelationships;
|
||||
use App\Console\Commands\MakeModelWithRelationships;
|
||||
use App\Console\Commands\GenerateSimpleRelationships;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user