Files
sam-api/app/Services/Quote/FormulaHandlerFactory.php

39 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Services\Quote;
use App\Services\Quote\Contracts\TenantFormulaHandler;
/**
* 테넌트별 수식 핸들러 팩토리 (Zero Config)
*
* tenant_id 기반 자동 발견: Handlers/Tenant{id}/FormulaHandler.php 존재 여부로 라우팅.
* 설정 파일, DB 매핑, options 없이 클래스 존재 여부만으로 핸들러를 결정한다.
*
* 업체 추가: Handlers/Tenant{id}/FormulaHandler.php 1개만 생성하면 자동 인식.
*/
class FormulaHandlerFactory
{
/**
* 테넌트 전용 핸들러 생성 (없으면 null Generic DB 경로)
*/
public static function make(int $tenantId): ?TenantFormulaHandler
{
$class = "App\\Services\\Quote\\Handlers\\Tenant{$tenantId}\\FormulaHandler";
if (! class_exists($class)) {
return null;
}
$handler = new $class;
if (! $handler instanceof TenantFormulaHandler) {
throw new \RuntimeException(
"Handler [{$class}] must implement " . TenantFormulaHandler::class
);
}
return $handler;
}
}