namespace App\Services\Api; use App\Models\ApiProvider; use App\Services\Api\Providers\StandardApiProvider; use App\Services\Api\Providers\AdvancedApiProvider; use App\Exceptions\ApiProviderException; class ApiServiceFactory { /** * Create API provider instance */ public function create(ApiProvider $provider): ApiProviderInterface { switch ($provider->api_type) { case 'standard': return new StandardApiProvider($provider); case 'advanced': return new AdvancedApiProvider($provider); case 'custom': return $this->createCustomProvider($provider); default: throw new ApiProviderException("Unsupported API type: {$provider->api_type}"); } } /** * Create custom provider */ protected function createCustomProvider(ApiProvider $provider): ApiProviderInterface { $className = "App\\Services\\Api\\Providers\\Custom\\" . studly_case($provider->code) . "Provider"; if (!class_exists($className)) { throw new ApiProviderException("Custom provider class not found: {$className}"); } return new $className($provider); } }