feat(api): implement javascript-first architecture for cache compatibility
- Add REST endpoint GET /roi-theme/v1/adsense-placement/visibility - Add Domain layer: UserContext, VisibilityDecision, AdsenseSettings VOs - Add Application layer: CheckAdsenseVisibilityUseCase - Add Infrastructure: AdsenseVisibilityChecker, Controller, Enqueuer - Add JavaScript controller with localStorage caching - Add test plan for production validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Public\AdsensePlacement\Infrastructure\Providers;
|
||||
|
||||
use ROITheme\Shared\Infrastructure\Di\DIContainer;
|
||||
use ROITheme\Public\AdsensePlacement\Domain\Contracts\AdsenseVisibilityCheckerInterface;
|
||||
use ROITheme\Public\AdsensePlacement\Infrastructure\Services\AdsenseVisibilityChecker;
|
||||
use ROITheme\Public\AdsensePlacement\Application\UseCases\CheckAdsenseVisibilityUseCase;
|
||||
use ROITheme\Public\AdsensePlacement\Infrastructure\Api\WordPress\AdsenseVisibilityController;
|
||||
use ROITheme\Public\AdsensePlacement\Infrastructure\Ui\AdsenseAssetsEnqueuer;
|
||||
|
||||
/**
|
||||
* Service Provider para el sistema JavaScript-First de AdSense.
|
||||
*
|
||||
* Registra todas las dependencias y hooks necesarios.
|
||||
*
|
||||
* @package ROITheme\Public\AdsensePlacement\Infrastructure\Providers
|
||||
*/
|
||||
final class AdsenseJavascriptFirstServiceProvider
|
||||
{
|
||||
private ?AdsenseVisibilityCheckerInterface $visibilityChecker = null;
|
||||
private ?CheckAdsenseVisibilityUseCase $useCase = null;
|
||||
private ?AdsenseVisibilityController $controller = null;
|
||||
private ?AdsenseAssetsEnqueuer $enqueuer = null;
|
||||
|
||||
public function __construct(
|
||||
private DIContainer $container
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registra los servicios en el contenedor.
|
||||
*
|
||||
* Llamar en after_setup_theme.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
// Los servicios se crean lazy en boot()
|
||||
}
|
||||
|
||||
/**
|
||||
* Inicializa los hooks de WordPress.
|
||||
*
|
||||
* Llamar en init.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
// Registrar REST API endpoint
|
||||
add_action('rest_api_init', function(): void {
|
||||
$this->getController()->registerRoutes();
|
||||
});
|
||||
|
||||
// Registrar enqueue de assets
|
||||
$this->getEnqueuer()->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el checker de visibilidad (lazy initialization).
|
||||
*/
|
||||
public function getVisibilityChecker(): AdsenseVisibilityCheckerInterface
|
||||
{
|
||||
if ($this->visibilityChecker === null) {
|
||||
$this->visibilityChecker = new AdsenseVisibilityChecker(
|
||||
$this->container->getComponentSettingsRepository()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->visibilityChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el use case (lazy initialization).
|
||||
*/
|
||||
public function getUseCase(): CheckAdsenseVisibilityUseCase
|
||||
{
|
||||
if ($this->useCase === null) {
|
||||
$this->useCase = new CheckAdsenseVisibilityUseCase(
|
||||
$this->getVisibilityChecker()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->useCase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el controller REST (lazy initialization).
|
||||
*/
|
||||
public function getController(): AdsenseVisibilityController
|
||||
{
|
||||
if ($this->controller === null) {
|
||||
$this->controller = new AdsenseVisibilityController(
|
||||
$this->getUseCase()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el enqueuer de assets (lazy initialization).
|
||||
*/
|
||||
public function getEnqueuer(): AdsenseAssetsEnqueuer
|
||||
{
|
||||
if ($this->enqueuer === null) {
|
||||
$this->enqueuer = new AdsenseAssetsEnqueuer(
|
||||
$this->container->getComponentSettingsRepository()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->enqueuer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user