- Add ArchiveHeader component (schema, renderer, formbuilder) - Add PostGrid component (schema, renderer, formbuilder) - Unify archive templates (home, archive, category, tag, author, date, search) - Add page visibility system with VisibilityDefaults - Register components in AdminDashboardRenderer - Fix boolean conversion in functions-addon.php - All 172 unit tests passed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace ROITheme\Shared\Application\UseCases\EvaluatePageVisibility;
|
|
|
|
use ROITheme\Shared\Domain\Contracts\PageTypeDetectorInterface;
|
|
use ROITheme\Shared\Domain\Contracts\PageVisibilityRepositoryInterface;
|
|
use ROITheme\Shared\Domain\Constants\VisibilityDefaults;
|
|
|
|
/**
|
|
* Caso de uso: Evaluar si un componente debe mostrarse en la página actual
|
|
*
|
|
* @package ROITheme\Shared\Application\UseCases\EvaluatePageVisibility
|
|
*/
|
|
final class EvaluatePageVisibilityUseCase
|
|
{
|
|
// NOTA: Usa VisibilityDefaults::DEFAULT_VISIBILITY para cumplir DRY
|
|
|
|
public function __construct(
|
|
private readonly PageTypeDetectorInterface $pageTypeDetector,
|
|
private readonly PageVisibilityRepositoryInterface $visibilityRepository
|
|
) {}
|
|
|
|
/**
|
|
* Evalua si el componente debe mostrarse en la pagina actual
|
|
*/
|
|
public function execute(string $componentName): bool
|
|
{
|
|
$config = $this->visibilityRepository->getVisibilityConfig($componentName);
|
|
|
|
if (empty($config)) {
|
|
// Usar defaults especificos por componente si existen
|
|
$config = VisibilityDefaults::getForComponent($componentName);
|
|
}
|
|
|
|
$pageType = $this->pageTypeDetector->detect();
|
|
$visibilityField = $pageType->toVisibilityField();
|
|
|
|
return $this->toBool($config[$visibilityField] ?? true);
|
|
}
|
|
|
|
private function toBool(mixed $value): bool
|
|
{
|
|
return $value === true || $value === '1' || $value === 1;
|
|
}
|
|
}
|