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>
87 lines
1.8 KiB
PHP
87 lines
1.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace ROITheme\Shared\Domain\ValueObjects;
|
|
|
|
/**
|
|
* Value Object: Exclusion por ID de post/pagina
|
|
*
|
|
* Evalua si el post/pagina actual esta en la lista de IDs excluidos.
|
|
*
|
|
* @package ROITheme\Shared\Domain\ValueObjects
|
|
*/
|
|
final class PostIdExclusion extends ExclusionRule
|
|
{
|
|
/**
|
|
* @param array<int> $excludedPostIds Lista de IDs de posts/paginas
|
|
*/
|
|
public function __construct(
|
|
private readonly array $excludedPostIds = []
|
|
) {}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* Contexto esperado:
|
|
* - post_id: int
|
|
*/
|
|
public function matches(array $context): bool
|
|
{
|
|
if (!$this->hasValues()) {
|
|
return false;
|
|
}
|
|
|
|
$postId = $context['post_id'] ?? 0;
|
|
|
|
if ($postId === 0) {
|
|
return false;
|
|
}
|
|
|
|
return in_array($postId, $this->excludedPostIds, true);
|
|
}
|
|
|
|
public function hasValues(): bool
|
|
{
|
|
return !empty($this->excludedPostIds);
|
|
}
|
|
|
|
public function serialize(): string
|
|
{
|
|
return json_encode($this->excludedPostIds);
|
|
}
|
|
|
|
/**
|
|
* @return array<int>
|
|
*/
|
|
public function getExcludedPostIds(): array
|
|
{
|
|
return $this->excludedPostIds;
|
|
}
|
|
|
|
/**
|
|
* Crea instancia desde JSON
|
|
*/
|
|
public static function fromJson(string $json): self
|
|
{
|
|
$decoded = json_decode($json, true);
|
|
|
|
if (!is_array($decoded)) {
|
|
return self::empty();
|
|
}
|
|
|
|
// Asegurar que son enteros
|
|
$ids = array_map('intval', $decoded);
|
|
$ids = array_filter($ids, fn(int $id): bool => $id > 0);
|
|
|
|
return new self(array_values($ids));
|
|
}
|
|
|
|
/**
|
|
* Crea instancia vacia
|
|
*/
|
|
public static function empty(): self
|
|
{
|
|
return new self([]);
|
|
}
|
|
}
|