| | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | | } |
| | | use JVBase\managers\queue\mergers\DefaultMerger; |
| | | |
| | | final class TypeRegistry |
| | | { |
| | |
| | | |
| | | public function register(string $type, TypeConfig $config): void |
| | | { |
| | | $this->validateRegistration($type, $config); |
| | | $this->configs[$type] = $config; |
| | | } |
| | | |
| | |
| | | |
| | | public function getMergeable(string $type): ?Mergeable |
| | | { |
| | | return $this->configs[$type]?->mergeable; |
| | | $config = $this->configs[$type] ?? null; |
| | | if (!$config) { |
| | | return null; |
| | | } |
| | | |
| | | // Explicit mergeable always wins |
| | | if ($config->mergeable) { |
| | | return $config->mergeable; |
| | | } |
| | | |
| | | // Default merge based on chunkKey |
| | | if ($config->chunkKey) { |
| | | return new DefaultMerger($config->chunkKey); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | public function getConfig(string $type): ?TypeConfig |
| | |
| | | { |
| | | return $this->configs[$type]?->maxRetries ?? 3; |
| | | } |
| | | |
| | | public function validateRegistration(string $type, TypeConfig $config): void |
| | | { |
| | | if ($config->executor && $config->chunkKey) { |
| | | // Verify executor can handle chunked operations |
| | | if (!method_exists($config->executor, 'execute')) { |
| | | throw new \InvalidArgumentException( |
| | | "Executor for '{$type}' must implement execute() method" |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |