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>
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace ROITheme\Shared\Application\UseCases\EvaluateExclusions;
|
|
|
|
use ROITheme\Shared\Domain\Contracts\ExclusionRepositoryInterface;
|
|
use ROITheme\Shared\Domain\Contracts\PageContextProviderInterface;
|
|
|
|
/**
|
|
* Caso de uso: Evaluar si un componente debe excluirse en la pagina actual
|
|
*
|
|
* Obtiene las reglas de exclusion del repositorio y evalua si aplican
|
|
* al contexto actual (post ID, categorias, URL).
|
|
*
|
|
* DIP: Depende de interfaces, no implementaciones.
|
|
*
|
|
* @package ROITheme\Shared\Application\UseCases\EvaluateExclusions
|
|
*/
|
|
final class EvaluateExclusionsUseCase
|
|
{
|
|
public function __construct(
|
|
private readonly ExclusionRepositoryInterface $exclusionRepository,
|
|
private readonly PageContextProviderInterface $contextProvider
|
|
) {}
|
|
|
|
/**
|
|
* Evalua si el componente debe excluirse
|
|
*
|
|
* @param string $componentName Nombre del componente (kebab-case)
|
|
* @return bool True si debe EXCLUIRSE (NO mostrar)
|
|
*/
|
|
public function execute(string $componentName): bool
|
|
{
|
|
$exclusions = $this->exclusionRepository->getExclusions($componentName);
|
|
|
|
if (!$exclusions->isEnabled()) {
|
|
return false;
|
|
}
|
|
|
|
$context = $this->contextProvider->getCurrentContext();
|
|
|
|
return $exclusions->shouldExclude($context);
|
|
}
|
|
}
|