This commit is contained in:
team 1
2026-05-05 12:12:51 +02:00
parent da374edcf4
commit 2c041a88c0
12 changed files with 429 additions and 282 deletions

View File

@@ -13,6 +13,7 @@ final class CommerceQueryParserConfig
*/
public function __construct(
private readonly array $config = [],
private readonly ?DomainVocabularyConfig $vocabulary = null,
) {
}
@@ -268,7 +269,10 @@ final class CommerceQueryParserConfig
/** @return string[] */
public function getSemanticShopSearchTokens(): array
{
return $this->stringList('semantic_shop_search_tokens');
return $this->configuredStringListOrVocabularyView(
'semantic_shop_search_tokens',
'vocabulary_views.semantic_shop_search_tokens'
);
}
public function buildExactTokenRemovalPattern(string $token): string
@@ -319,6 +323,27 @@ final class CommerceQueryParserConfig
return $out;
}
/** @return string[] */
private function configuredStringListOrVocabularyView(string $configPath, string $viewPathConfigPath): array
{
if ($this->hasPath($configPath)) {
return $this->stringList($configPath);
}
if ($this->vocabulary === null) {
throw $this->missing($configPath);
}
$viewPath = $this->string($viewPathConfigPath);
$terms = $this->vocabulary->view($viewPath, []);
if ($terms === []) {
throw $this->invalid($viewPathConfigPath, sprintf('references empty vocabulary view "%s"', $viewPath));
}
return $terms;
}
/** @return array<string, string> */
private function stringMap(string $path): array
{
@@ -372,6 +397,20 @@ final class CommerceQueryParserConfig
return $value;
}
private function hasPath(string $path): bool
{
$current = $this->config;
foreach (explode('.', $path) as $segment) {
if (!is_array($current) || !array_key_exists($segment, $current)) {
return false;
}
$current = $current[$segment];
}
return true;
}
private function value(string $path): mixed
{
$current = $this->config;