Adds ability to exclude components from specific: - Categories (by slug or term_id) - Post/Page IDs - URL patterns (substring or regex) Architecture: - Domain: Value Objects (CategoryExclusion, PostIdExclusion, UrlPatternExclusion, ExclusionRuleSet) + Contracts - Application: EvaluateExclusionsUseCase + EvaluateComponentVisibilityUseCase (orchestrator) - Infrastructure: WordPressExclusionRepository, WordPressPageContextProvider, WordPressServerRequestProvider - Admin: ExclusionFormPartial (reusable UI), ExclusionFieldProcessor, JS toggle The PageVisibilityHelper now uses the orchestrator UseCase that combines page-type visibility (Plan 99.10) with exclusion rules. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace ROITheme\Admin\Shared\Infrastructure\Services;
|
|
|
|
/**
|
|
* Servicio para procesar campos de exclusion antes de guardar en BD
|
|
*
|
|
* Convierte formatos de UI a JSON para almacenamiento.
|
|
*
|
|
* v1.1: Extraido de AdminAjaxHandler (SRP)
|
|
*
|
|
* @package ROITheme\Admin\Shared\Infrastructure\Services
|
|
*/
|
|
final class ExclusionFieldProcessor
|
|
{
|
|
/**
|
|
* Procesa un valor de campo de exclusion segun su tipo
|
|
*
|
|
* @param string $value Valor del campo (desde UI)
|
|
* @param string $type Tipo de campo: json_array, json_array_int, json_array_lines
|
|
* @return string JSON string para almacenar en BD
|
|
*/
|
|
public function process(string $value, string $type): string
|
|
{
|
|
return match ($type) {
|
|
'json_array' => $this->processJsonArray($value),
|
|
'json_array_int' => $this->processJsonArrayInt($value),
|
|
'json_array_lines' => $this->processJsonArrayLines($value),
|
|
default => $value,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* "a, b, c" -> ["a", "b", "c"]
|
|
*/
|
|
private function processJsonArray(string $value): string
|
|
{
|
|
$items = array_map('trim', explode(',', $value));
|
|
$items = array_filter($items, fn($item) => $item !== '');
|
|
return json_encode(array_values($items), JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
/**
|
|
* "1, 2, 3" -> [1, 2, 3]
|
|
*/
|
|
private function processJsonArrayInt(string $value): string
|
|
{
|
|
$items = array_map('trim', explode(',', $value));
|
|
$items = array_filter($items, 'is_numeric');
|
|
$items = array_map('intval', $items);
|
|
return json_encode(array_values($items));
|
|
}
|
|
|
|
/**
|
|
* Lineas separadas -> array
|
|
*/
|
|
private function processJsonArrayLines(string $value): string
|
|
{
|
|
$items = preg_split('/\r\n|\r|\n/', $value);
|
|
$items = array_map('trim', $items);
|
|
$items = array_filter($items, fn($item) => $item !== '');
|
|
return json_encode(array_values($items), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
|
}
|
|
}
|