$domains * @param array $capabilities * @param array $configSchema */ public function __construct(string $key, mixed ...$arguments) { if (($arguments[0] ?? null) instanceof ProviderCapability) { $this->initializeLegacy($key, $arguments); return; } [ $displayName, $domains, $capabilities, $configurable, $requiresApiKey, $apiKeyField, $defaultEnabled, $defaultOrder, $defaultTimeout, $configSchema, $runtimeAvailable, $searchAvailable, $licensingClass, ] = array_slice(array_pad($arguments, 20, null), 0, 13); $supportsIdentifierSearch = $arguments[13] ?? null; $supportsTitleSearch = $arguments[14] ?? null; $supportsBarcodeSearch = $arguments[15] ?? null; $supportsImage = $arguments[16] ?? null; $supportsMetadata = $arguments[17] ?? null; $supportsPrice = $arguments[18] ?? null; $supportsDescription = $arguments[19] ?? null; $normalizedKey = $this->normalizeKey($key); if ($normalizedKey === '') { throw new InvalidArgumentException('Provider key cannot be empty.'); } if ($displayName === '') { throw new InvalidArgumentException('Provider display name cannot be empty.'); } if ($domains === []) { throw new InvalidArgumentException('Provider domains cannot be empty.'); } if ($defaultOrder !== null && $defaultOrder < 0) { throw new InvalidArgumentException('Provider default order cannot be negative.'); } if ($defaultTimeout !== null && $defaultTimeout < 0) { throw new InvalidArgumentException('Provider default timeout cannot be negative.'); } $this->key = $normalizedKey; $this->displayName = $displayName; $this->domains = array_values(array_map('strval', $domains)); $this->capabilities = $capabilities; $this->configurable = $configurable; $this->requiresApiKey = $requiresApiKey; $this->apiKeyField = $apiKeyField !== null && trim($apiKeyField) !== '' ? trim($apiKeyField) : null; $this->defaultEnabled = $defaultEnabled; $this->defaultOrder = $defaultOrder; $this->defaultTimeout = $defaultTimeout; $this->configSchema = $configSchema; $this->runtimeAvailable = $runtimeAvailable; $this->searchAvailable = $searchAvailable; $this->licensingClass = $licensingClass; $this->supportsIdentifierSearch = $supportsIdentifierSearch; $this->supportsTitleSearch = $supportsTitleSearch; $this->supportsBarcodeSearch = $supportsBarcodeSearch; $this->supportsImage = $supportsImage; $this->supportsMetadata = $supportsMetadata; $this->supportsPrice = $supportsPrice; $this->supportsDescription = $supportsDescription; } private function initializeLegacy(string $name, array $arguments): void { $this->legacyCapability = $arguments[0]; $this->legacyMetadata = $arguments[1]; $this->legacyStatistics = $arguments[2]; $this->legacyHealth = $arguments[3]; $this->legacyLimitations = $arguments[4]; $this->legacyLicense = $arguments[5]; $this->priority = (int) ($arguments[6] ?? 0); $this->key = $this->normalizeKey($name); $this->displayName = $name; $this->domains = $this->legacyCapability->getSupportedDomains(); $this->capabilities = []; $this->configurable = true; $this->requiresApiKey = false; $this->apiKeyField = null; $this->defaultEnabled = null; $this->defaultOrder = null; $this->defaultTimeout = null; $this->configSchema = []; $this->runtimeAvailable = $this->legacyHealth->getStatus() === ProviderHealth::ACTIVE; $this->searchAvailable = $this->runtimeAvailable; $this->licensingClass = $this->legacyLicense->allowsCommercialUsage() ? 'commercial' : 'restricted'; $this->supportsIdentifierSearch = true; $this->supportsTitleSearch = true; $this->supportsBarcodeSearch = null; $this->supportsImage = $this->legacyCapability->providesImages(); $this->supportsMetadata = true; $this->supportsPrice = $this->legacyCapability->hasPriceSupport(); $this->supportsDescription = true; } public function getKey(): string { return $this->key; } public function getDisplayName(): string { return $this->displayName; } /** * @return array */ public function getDomains(): array { return $this->domains; } /** * @return array */ public function getCapabilities(): array { return $this->capabilities; } public function isConfigurable(): bool { return $this->configurable; } public function requiresApiKey(): bool { return $this->requiresApiKey; } public function getApiKeyField(): ?string { return $this->apiKeyField; } public function getDefaultEnabled(): ?bool { return $this->defaultEnabled; } public function getDefaultOrder(): ?int { return $this->defaultOrder; } public function getDefaultTimeout(): ?int { return $this->defaultTimeout; } /** * @return array */ public function getConfigSchema(): array { return $this->configSchema; } public function isRuntimeAvailable(): bool { return $this->runtimeAvailable; } public function isSearchAvailable(): bool { return $this->searchAvailable; } public function getLicensingClass(): string { return $this->licensingClass; } public function supportsIdentifierSearch(): ?bool { return $this->supportsIdentifierSearch; } public function supportsTitleSearch(): ?bool { return $this->supportsTitleSearch; } public function supportsBarcodeSearch(): ?bool { return $this->supportsBarcodeSearch; } public function supportsImage(): ?bool { return $this->supportsImage; } public function supportsMetadata(): ?bool { return $this->supportsMetadata; } public function supportsPrice(): ?bool { return $this->supportsPrice; } public function supportsDescription(): ?bool { return $this->supportsDescription; } public function getName(): string { return $this->displayName; } public function getSupportedDomains(): array { return $this->legacyCapability?->getSupportedDomains() ?? $this->domains; } public function getSupportedIdentifierTypes(): array { return $this->legacyCapability?->getSupportedIdentifierTypes() ?? []; } public function getPriority(): int { return $this->priority; } public function getStatus(): string { return $this->legacyHealth?->getStatus() ?? ($this->runtimeAvailable ? ProviderHealth::ACTIVE : ProviderHealth::PLANNED); } public function getMetadataQuality(): float { return $this->legacyCapability?->getMetadataQuality() ?? 0.0; } public function getSeoQuality(): float { return $this->legacyCapability?->getSeoQuality() ?? 0.0; } public function getImageQuality(): float { return $this->legacyCapability?->getImageQuality() ?? 0.0; } public function getDescriptionQuality(): float { return $this->legacyCapability?->getDescriptionQuality() ?? 0.0; } public function getAttributesQuality(): float { return $this->legacyCapability?->getAttributesQuality() ?? 0.0; } public function getCategoryQuality(): float { return $this->legacyCapability?->getCategoryQuality() ?? 0.0; } public function getBrandQuality(): float { return $this->legacyCapability?->getBrandQuality() ?? 0.0; } public function hasPriceSupport(): bool { return $this->legacyCapability?->hasPriceSupport() ?? (bool) $this->supportsPrice; } public function getLanguageCoverage(): array { return $this->legacyMetadata?->getLanguages() ?? ['*']; } public function getCountryCoverage(): array { return $this->legacyMetadata?->getCountries() ?? ['*']; } public function allowsCommercialUsage(): bool { return $this->legacyLicense?->allowsCommercialUsage() ?? $this->licensingClass === 'commercial'; } public function allowsPersistence(): bool { return $this->legacyLicense?->allowsPersistence() ?? false; } public function getCachingPolicy(): string { return $this->legacyMetadata?->getCachingPolicy() ?? 'provider terms apply'; } public function getPersistencePolicy(): string { return $this->legacyMetadata?->getPersistencePolicy() ?? 'restricted'; } public function getRateLimits(): array { return $this->legacyMetadata?->getRateLimits() ?? []; } public function getAuthentication(): string { return $this->legacyMetadata?->getAuthentication() ?? ($this->requiresApiKey ? 'api_key' : 'none'); } public function getReliability(): float { return $this->legacyHealth?->getReliability() ?? 0.0; } public function getEstimatedSpeed(): float { return $this->legacyHealth?->getEstimatedSpeed() ?? 0.0; } public function supportsDomain(string $domain): bool { if ($this->legacyCapability !== null) return $this->legacyCapability->supportsDomain($domain); foreach ($this->domains as $supported) if (strcasecmp($supported, $domain) === 0) return true; return false; } public function supportsIdentifierType(string $identifierType): bool { return $this->legacyCapability?->supportsIdentifierType($identifierType) ?? false; } public function getCapability(): ProviderCapability { return $this->legacyCapability ?? new ProviderCapability($this->domains, [], [], (bool) $this->supportsPrice); } public function getMetadata(): ProviderMetadata { return $this->legacyMetadata ?? new ProviderMetadata(['*'], ['*'], 'provider terms apply', 'restricted', [], $this->getAuthentication()); } public function getStatistics(): ProviderStatistics { return $this->legacyStatistics ?? new ProviderStatistics([]); } public function getHealth(): ProviderHealth { return $this->legacyHealth ?? new ProviderHealth(0.0, 0.0, $this->getStatus()); } public function getLimitations(): ProviderLimitations { return $this->legacyLimitations ?? new ProviderLimitations([]); } public function getLicense(): ProviderLicense { return $this->legacyLicense ?? new ProviderLicense($this->licensingClass, $this->allowsCommercialUsage(), false, false); } private function normalizeKey(string $key): string { $normalized = preg_replace('/[^a-zA-Z0-9]+/', '', trim($key)); return is_string($normalized) ? $normalized : ''; } }