feat(exclusions): Implement component exclusion system (Plan 99.11)
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>
This commit is contained in:
100
Shared/Domain/ValueObjects/ExclusionRuleSet.php
Normal file
100
Shared/Domain/ValueObjects/ExclusionRuleSet.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Domain\ValueObjects;
|
||||
|
||||
/**
|
||||
* Value Object Compuesto: Conjunto de reglas de exclusion
|
||||
*
|
||||
* Agrupa todas las reglas de exclusion para un componente.
|
||||
* Evalua con logica OR (si cualquier regla coincide, se excluye).
|
||||
*
|
||||
* @package ROITheme\Shared\Domain\ValueObjects
|
||||
*/
|
||||
final class ExclusionRuleSet
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $componentName,
|
||||
private readonly bool $enabled,
|
||||
private readonly CategoryExclusion $categoryExclusion,
|
||||
private readonly PostIdExclusion $postIdExclusion,
|
||||
private readonly UrlPatternExclusion $urlPatternExclusion
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Evalua si el componente debe excluirse segun el contexto actual
|
||||
*
|
||||
* @param array<string, mixed> $context Contexto de la pagina actual
|
||||
* @return bool True si debe excluirse (NO mostrar)
|
||||
*/
|
||||
public function shouldExclude(array $context): bool
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Evaluar cada tipo de exclusion (OR logico)
|
||||
if ($this->categoryExclusion->matches($context)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->postIdExclusion->matches($context)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->urlPatternExclusion->matches($context)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifica si tiene alguna regla configurada
|
||||
*/
|
||||
public function hasAnyRule(): bool
|
||||
{
|
||||
return $this->categoryExclusion->hasValues()
|
||||
|| $this->postIdExclusion->hasValues()
|
||||
|| $this->urlPatternExclusion->hasValues();
|
||||
}
|
||||
|
||||
public function getComponentName(): string
|
||||
{
|
||||
return $this->componentName;
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
public function getCategoryExclusion(): CategoryExclusion
|
||||
{
|
||||
return $this->categoryExclusion;
|
||||
}
|
||||
|
||||
public function getPostIdExclusion(): PostIdExclusion
|
||||
{
|
||||
return $this->postIdExclusion;
|
||||
}
|
||||
|
||||
public function getUrlPatternExclusion(): UrlPatternExclusion
|
||||
{
|
||||
return $this->urlPatternExclusion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una instancia sin exclusiones (por defecto)
|
||||
*/
|
||||
public static function empty(string $componentName): self
|
||||
{
|
||||
return new self(
|
||||
$componentName,
|
||||
false,
|
||||
CategoryExclusion::empty(),
|
||||
PostIdExclusion::empty(),
|
||||
UrlPatternExclusion::empty()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user