fix(structure): Correct case-sensitivity for Linux compatibility

Rename folders to match PHP PSR-4 autoloading conventions:
- schemas → Schemas
- shared → Shared
- Wordpress → WordPress (in all locations)

Fixes deployment issues on Linux servers where filesystem is case-sensitive.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-11-26 22:53:34 -06:00
parent a2548ab5c2
commit 90863cd8f5
92 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace ROITheme\Shared\Application\UseCases\SaveComponent;
/**
* SaveComponentRequest - DTO de entrada para guardar componente
*
* RESPONSABILIDAD: Encapsular los datos de entrada para el Use Case de guardar un componente
*
* CARACTER<45>STICAS:
* - Inmutable
* - Sin l<>gica de negocio
* - Validaci<63>n b<>sica de tipos (PHP har<61> type checking)
*
* USO:
* ```php
* $request = new SaveComponentRequest('top_bar', [
* 'configuration' => ['content' => ['message_text' => 'Welcome']],
* 'visibility' => ['desktop' => true, 'mobile' => true],
* 'is_enabled' => true
* ]);
* ```
*
* @package ROITheme\Shared\Application\UseCases\SaveComponent
*/
final readonly class SaveComponentRequest
{
/**
* @param string $componentName Nombre del componente a guardar (e.g., 'top_bar', 'footer_cta')
* @param array $data Datos del componente (configuration, visibility, is_enabled, schema_version)
*/
public function __construct(
private string $componentName,
private array $data
) {}
/**
* Obtener nombre del componente
*
* @return string
*/
public function getComponentName(): string
{
return $this->componentName;
}
/**
* Obtener datos del componente
*
* @return array
*/
public function getData(): array
{
return $this->data;
}
/**
* Factory method: Crear desde array
*
* <20>til para crear desde datos POST/JSON
*
* @param array $data Array con keys 'component_name' y 'data'
* @return self
*/
public static function fromArray(array $data): self
{
return new self(
$data['component_name'] ?? '',
$data['data'] ?? []
);
}
}

View File

@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace ROITheme\Shared\Application\UseCases\SaveComponent;
/**
* SaveComponentResponse - DTO de salida para guardar componente
*
* RESPONSABILIDAD: Encapsular el resultado del Use Case (<28>xito o fallo)
*
* PATR<54>N: Success/Failure
* - <20>xito: success=true, data contiene el componente guardado
* - Fallo: success=false, errors contiene array de errores
*
* CARACTER<45>STICAS:
* - Inmutable
* - Constructor privado (usar factory methods)
* - Factory methods: success() y failure()
*
* USO:
* ```php
* // <20>xito
* $response = SaveComponentResponse::success(['name' => 'top_bar', ...]);
* if ($response->isSuccess()) {
* $data = $response->getData();
* }
*
* // Fallo
* $response = SaveComponentResponse::failure(['Error de validaci<63>n']);
* if (!$response->isSuccess()) {
* $errors = $response->getErrors();
* }
* ```
*
* @package ROITheme\Shared\Application\UseCases\SaveComponent
*/
final readonly class SaveComponentResponse
{
/**
* Constructor privado - usar factory methods
*
* @param bool $success Indica si la operaci<63>n fue exitosa
* @param mixed $data Datos del componente guardado (solo si success=true)
* @param array|null $errors Array de errores (solo si success=false)
*/
private function __construct(
private bool $success,
private mixed $data,
private ?array $errors
) {}
/**
* Verificar si la operaci<63>n fue exitosa
*
* @return bool
*/
public function isSuccess(): bool
{
return $this->success;
}
/**
* Obtener datos del componente guardado
*
* Solo v<>lido si isSuccess() === true
*
* @return mixed
*/
public function getData(): mixed
{
return $this->data;
}
/**
* Obtener errores
*
* Solo v<>lido si isSuccess() === false
*
* @return array|null
*/
public function getErrors(): ?array
{
return $this->errors;
}
/**
* Factory method: Crear respuesta exitosa
*
* @param mixed $data Datos del componente guardado
* @return self
*/
public static function success(mixed $data): self
{
return new self(true, $data, null);
}
/**
* Factory method: Crear respuesta de fallo
*
* @param array $errors Array de mensajes de error
* @return self
*/
public static function failure(array $errors): self
{
return new self(false, null, $errors);
}
/**
* Convertir a array para serializaci<63>n (JSON, etc.)
*
* @return array
*/
public function toArray(): array
{
return [
'success' => $this->success,
'data' => $this->data,
'errors' => $this->errors
];
}
}

View File

@@ -0,0 +1,143 @@
<?php
declare(strict_types=1);
namespace ROITheme\Shared\Application\UseCases\SaveComponent;
use ROITheme\Shared\Domain\Entities\Component;
use ROITheme\Shared\Domain\ValueObjects\ComponentName;
use ROITheme\Shared\Domain\ValueObjects\ComponentConfiguration;
use ROITheme\Shared\Domain\ValueObjects\ComponentVisibility;
use ROITheme\Shared\Domain\Contracts\ComponentRepositoryInterface;
use ROITheme\Shared\Domain\Contracts\ValidationServiceInterface;
use ROITheme\Shared\Domain\Contracts\CacheServiceInterface;
use ROITheme\Shared\Domain\Exceptions\InvalidComponentException;
/**
* SaveComponentUseCase - Caso de Uso para guardar componente
*
* RESPONSABILIDAD: Orquestar la lógica de guardar un componente
*
* FLUJO:
* 1. Validar datos contra schema
* 2. Obtener datos sanitizados del resultado de validación
* 3. Crear entidad de dominio (Component)
* 4. Persistir en repositorio
* 5. Invalidar cache
* 6. Retornar respuesta
*
* PRINCIPIOS APLICADOS:
* - Single Responsibility: Solo orquesta, no tiene lógica de negocio
* - Dependency Inversion: Depende de interfaces, no implementaciones
* - Open/Closed: Extensible via cambio de implementaciones
*
* USO:
* ```php
* $useCase = new SaveComponentUseCase($repository, $validator, $cache);
* $request = new SaveComponentRequest('top_bar', $data);
* $response = $useCase->execute($request);
*
* if ($response->isSuccess()) {
* // Éxito
* }
* ```
*
* @package ROITheme\Shared\Application\UseCases\SaveComponent
*/
final class SaveComponentUseCase
{
/**
* @param ComponentRepositoryInterface $repository Repositorio de componentes
* @param ValidationServiceInterface $validator Servicio de validación
* @param CacheServiceInterface $cache Servicio de cache
*/
public function __construct(
private ComponentRepositoryInterface $repository,
private ValidationServiceInterface $validator,
private CacheServiceInterface $cache
) {}
/**
* Ejecutar Use Case
*
* @param SaveComponentRequest $request Datos de entrada
* @return SaveComponentResponse Respuesta (éxito o fallo)
*/
public function execute(SaveComponentRequest $request): SaveComponentResponse
{
try {
// 1. Validar datos contra schema
$validationResult = $this->validator->validate(
$request->getData(),
$request->getComponentName()
);
if (!$validationResult->isValid()) {
return SaveComponentResponse::failure($validationResult->getErrors());
}
// 2. Obtener datos sanitizados del resultado de validación
$sanitized = $validationResult->getSanitizedData();
// 3. Crear entidad de dominio
$component = $this->createComponent($request->getComponentName(), $sanitized);
// 4. Persistir (save() retorna Component guardado)
$savedComponent = $this->repository->save($component);
// 5. Invalidar cache
$this->cache->delete("component_{$request->getComponentName()}");
// 6. Retornar respuesta exitosa
return SaveComponentResponse::success($savedComponent->toArray());
} catch (InvalidComponentException $e) {
// Errores de dominio (validación de reglas de negocio)
return SaveComponentResponse::failure([$e->getMessage()]);
} catch (\Exception $e) {
// Errores inesperados
return SaveComponentResponse::failure([
'Unexpected error: ' . $e->getMessage()
]);
}
}
/**
* Crear entidad Component desde datos validados
*
* @param string $name Nombre del componente
* @param array $data Datos validados y sanitizados
* @return Component
* @throws InvalidComponentException Si los datos no cumplen invariantes
*/
private function createComponent(string $name, array $data): Component
{
// Extraer o usar valores por defecto
$isEnabled = $data['is_enabled'] ?? true;
$schemaVersion = $data['schema_version'] ?? '1.0.0';
// Extraer grupos de configuración (visibility, content, styles, general)
$configData = [
'visibility' => $data['visibility'] ?? [],
'content' => $data['content'] ?? [],
'styles' => $data['styles'] ?? [],
'general' => $data['general'] ?? []
];
// Los datos de visibility se manejan aparte en ComponentVisibility
$visibilityData = $data['visibility'] ?? [];
// Crear Value Objects
$componentName = new ComponentName($name);
$configuration = ComponentConfiguration::fromArray($configData);
$visibility = ComponentVisibility::fromArray($visibilityData);
// Crear entidad Component
return new Component(
$componentName,
$configuration,
$visibility,
$isEnabled,
$schemaVersion
);
}
}