central config part 1
This commit is contained in:
@@ -68,8 +68,10 @@ final class ShopServiceConfig
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
*/
|
||||
public function __construct(private array $config = [])
|
||||
{
|
||||
public function __construct(
|
||||
private array $config = [],
|
||||
private readonly ?DomainVocabularyConfig $vocabulary = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getTopProductLogLimit(): int
|
||||
@@ -80,43 +82,43 @@ final class ShopServiceConfig
|
||||
/** @return string[] */
|
||||
public function getDeviceFocusKeywords(): array
|
||||
{
|
||||
return $this->stringList('device_focus_keywords', self::DEVICE_FOCUS_KEYWORDS);
|
||||
return $this->stringList('device_focus_keywords', $this->vocabularyView('shop.device_focus', self::DEVICE_FOCUS_KEYWORDS));
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getAccessoryFocusKeywords(): array
|
||||
{
|
||||
return $this->stringList('accessory_focus_keywords', self::ACCESSORY_FOCUS_KEYWORDS);
|
||||
return $this->stringList('accessory_focus_keywords', $this->vocabularyView('shop.accessory_focus', self::ACCESSORY_FOCUS_KEYWORDS));
|
||||
}
|
||||
|
||||
/** @return array<string, string[]> */
|
||||
public function getAccessoryFocusVariantMap(): array
|
||||
{
|
||||
return $this->stringListMap('accessory_focus_variant_map', self::ACCESSORY_FOCUS_VARIANT_MAP);
|
||||
return $this->stringListMap('accessory_focus_variant_map', $this->vocabularyMap('shop.accessory_focus_variants', self::ACCESSORY_FOCUS_VARIANT_MAP));
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getDeviceQueryKeywords(): array
|
||||
{
|
||||
return $this->stringList('device_query_keywords', self::DEVICE_QUERY_KEYWORDS);
|
||||
return $this->stringList('device_query_keywords', $this->vocabularyView('shop.device_query', self::DEVICE_QUERY_KEYWORDS));
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getAccessoryQueryKeywords(): array
|
||||
{
|
||||
return $this->stringList('accessory_query_keywords', self::ACCESSORY_QUERY_KEYWORDS);
|
||||
return $this->stringList('accessory_query_keywords', $this->vocabularyView('shop.accessory_query', self::ACCESSORY_QUERY_KEYWORDS));
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getAccessoryProductKeywords(): array
|
||||
{
|
||||
return $this->stringList('accessory_product_keywords', self::ACCESSORY_PRODUCT_KEYWORDS);
|
||||
return $this->stringList('accessory_product_keywords', $this->vocabularyView('shop.accessory_product', self::ACCESSORY_PRODUCT_KEYWORDS));
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getDeviceProductKeywords(): array
|
||||
{
|
||||
return $this->stringList('device_product_keywords', self::DEVICE_PRODUCT_KEYWORDS);
|
||||
return $this->stringList('device_product_keywords', $this->vocabularyView('shop.device_product', self::DEVICE_PRODUCT_KEYWORDS));
|
||||
}
|
||||
|
||||
public function getExactProductNumberPhraseScore(): int
|
||||
@@ -368,6 +370,18 @@ final class ShopServiceConfig
|
||||
* @param string[]|null $emptySafeDefault
|
||||
* @return string[]
|
||||
*/
|
||||
/** @return string[] */
|
||||
private function vocabularyView(string $path, array $fallback): array
|
||||
{
|
||||
return $this->vocabulary?->view($path, $fallback) ?? $fallback;
|
||||
}
|
||||
|
||||
/** @return array<string, string[]> */
|
||||
private function vocabularyMap(string $path, array $fallback): array
|
||||
{
|
||||
return $this->vocabulary?->map($path, $fallback) ?? $fallback;
|
||||
}
|
||||
|
||||
private function stringList(string $path, array $default, bool $allowEmptyStrings = false, ?array $emptySafeDefault = null): array
|
||||
{
|
||||
$value = $this->value($path, $default);
|
||||
|
||||
Reference in New Issue
Block a user