22 lines
650 B
PHP
22 lines
650 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
class RsvFormPriceCalculatorRegistry {
|
||
|
|
/** @var array<string, callable(RsvFormElementDefinition, mixed): float> */
|
||
|
|
private array $calculators = [];
|
||
|
|
|
||
|
|
public function register(string $type, callable $calculator): void {
|
||
|
|
$this->calculators[$type] = $calculator;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get(string $type): ?callable {
|
||
|
|
return $this->calculators[$type] ?? null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Builds the registry and lets other modules contribute calculators. */
|
||
|
|
public static function boot(): self {
|
||
|
|
$registry = new self();
|
||
|
|
do_action('rsv-register-price-calculator', $registry);
|
||
|
|
return $registry;
|
||
|
|
}
|
||
|
|
}
|