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:
FrankZamora
2025-12-03 10:51:00 -06:00
parent 8735962f52
commit 14138e7762
19 changed files with 1407 additions and 5 deletions

View File

@@ -6,11 +6,11 @@ namespace ROITheme\Shared\Infrastructure\Services;
use ROITheme\Shared\Infrastructure\Di\DIContainer;
/**
* Facade/Helper para evaluar visibilidad de componentes
* Facade/Helper para evaluar visibilidad completa de componentes
*
* PROPÓSITO:
* Permite que los Renderers existentes evalúen visibilidad sin modificar sus constructores.
* Actúa como un Service Locator limitado a este único propósito.
* PROPOSITO:
* Permite que los Renderers existentes evaluen visibilidad sin modificar sus constructores.
* Ahora incluye tanto visibilidad por tipo de pagina como reglas de exclusion.
*
* USO EN RENDERERS:
* ```php
@@ -19,17 +19,41 @@ use ROITheme\Shared\Infrastructure\Di\DIContainer;
* }
* ```
*
* FLUJO:
* 1. Verifica visibilidad por tipo de pagina (home, posts, pages, etc.)
* 2. Verifica reglas de exclusion (categorias, IDs, patrones URL)
* 3. Retorna true SOLO si pasa ambas verificaciones
*
* @package ROITheme\Shared\Infrastructure\Services
*/
final class PageVisibilityHelper
{
/**
* Evalúa si un componente debe mostrarse en la página actual
* Evalua si un componente debe mostrarse en la pagina actual
*
* Incluye verificacion de:
* - Visibilidad por tipo de pagina (Plan 99.10)
* - Reglas de exclusion (Plan 99.11)
*
* @param string $componentName Nombre del componente (kebab-case)
* @return bool True si debe mostrarse
*/
public static function shouldShow(string $componentName): bool
{
$container = DIContainer::getInstance();
$useCase = $container->getEvaluateComponentVisibilityUseCase();
return $useCase->execute($componentName);
}
/**
* Evalua SOLO visibilidad por tipo de pagina (sin exclusiones)
*
* @deprecated Usar shouldShow() que incluye exclusiones
* @param string $componentName Nombre del componente (kebab-case)
* @return bool True si debe mostrarse segun tipo de pagina
*/
public static function shouldShowByPageType(string $componentName): bool
{
$container = DIContainer::getInstance();
$useCase = $container->getEvaluatePageVisibilityUseCase();

View File

@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace ROITheme\Shared\Infrastructure\Services;
use ROITheme\Shared\Domain\Contracts\PageContextProviderInterface;
use ROITheme\Shared\Domain\Contracts\ServerRequestProviderInterface;
/**
* Implementacion WordPress del proveedor de contexto de pagina
*
* Obtiene informacion del post/pagina actual usando funciones de WordPress.
*
* v1.1: Renombrado de WordPressExclusionEvaluator
* Inyecta ServerRequestProviderInterface (no accede a $_SERVER directamente)
*
* @package ROITheme\Shared\Infrastructure\Services
*/
final class WordPressPageContextProvider implements PageContextProviderInterface
{
public function __construct(
private readonly ServerRequestProviderInterface $requestProvider
) {}
public function getCurrentContext(): array
{
$postId = $this->getCurrentPostId();
return [
'post_id' => $postId,
'categories' => $this->getPostCategories($postId),
'url' => $this->getCurrentUrl(),
'request_uri' => $this->requestProvider->getRequestUri(),
'post_type' => $this->getCurrentPostType($postId),
];
}
private function getCurrentPostId(): int
{
if (is_singular()) {
return get_the_ID() ?: 0;
}
return 0;
}
/**
* @return array<array{term_id: int, slug: string, name: string}>
*/
private function getPostCategories(int $postId): array
{
if ($postId === 0) {
return [];
}
$categories = get_the_category($postId);
if (empty($categories)) {
return [];
}
return array_map(function (\WP_Term $term): array {
return [
'term_id' => $term->term_id,
'slug' => $term->slug,
'name' => $term->name,
];
}, $categories);
}
private function getCurrentUrl(): string
{
global $wp;
if (isset($wp->request)) {
return home_url($wp->request);
}
return home_url(add_query_arg([], false));
}
private function getCurrentPostType(int $postId): string
{
if ($postId === 0) {
return '';
}
return get_post_type($postId) ?: '';
}
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace ROITheme\Shared\Infrastructure\Services;
use ROITheme\Shared\Domain\Contracts\ServerRequestProviderInterface;
/**
* Implementacion WordPress del proveedor de request HTTP
*
* Encapsula el acceso a $_SERVER.
*
* v1.1: Nuevo - extrae logica de acceso a superglobales
*
* @package ROITheme\Shared\Infrastructure\Services
*/
final class WordPressServerRequestProvider implements ServerRequestProviderInterface
{
public function getRequestUri(): string
{
return $_SERVER['REQUEST_URI'] ?? '';
}
}