Fase 1: Estructura Base y DI Container - Clean Architecture

COMPLETADO: Fase 1 de la migración a Clean Architecture + POO

## Estructura de Carpetas
- ✓ Estructura completa de 4 capas (Domain, Application, Infrastructure, Presentation)
- ✓ Carpetas de Use Cases (SaveComponent, GetComponent, DeleteComponent, SyncSchema)
- ✓ Estructura de tests (Unit, Integration, E2E)
- ✓ Carpetas de schemas y templates

## Composer y Autoloading
- ✓ PSR-4 autoloading configurado para ROITheme namespace
- ✓ Autoloader optimizado regenerado

## DI Container
- ✓ DIContainer implementado con patrón Singleton
- ✓ Métodos set(), get(), has() para gestión de servicios
- ✓ Getters específicos para ComponentRepository, ValidationService, CacheService
- ✓ Placeholders que serán implementados en Fase 5
- ✓ Prevención de clonación y deserialización

## Interfaces
- ✓ ComponentRepositoryInterface (Domain)
- ✓ ValidationServiceInterface (Application)
- ✓ CacheServiceInterface (Application)
- ✓ Component entity placeholder (Domain)

## Bootstrap
- ✓ functions.php actualizado con carga de Composer autoloader
- ✓ Inicialización del DIContainer
- ✓ Helper function roi_container() disponible globalmente

## Tests
- ✓ 10 tests unitarios para DIContainer (100% cobertura)
- ✓ Total: 13 tests unitarios, 28 assertions
- ✓ Suite de tests pasando correctamente

## Validación
- ✓ Script de validación automatizado (48/48 checks pasados)
- ✓ 100% de validaciones exitosas

La arquitectura base está lista para la Fase 2.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-11-17 13:48:24 -06:00
parent b782ebceee
commit de5fff4f5c
149 changed files with 3187 additions and 9554 deletions

View File

@@ -6,7 +6,7 @@
* Sin placeholders - solo muestra imagen si existe.
* Issue #10 - Imágenes destacadas configurables
*
* @package Apus_Theme
* @package ROI_Theme
* @since 1.0.0
*/
@@ -24,17 +24,17 @@ if (!defined('ABSPATH')) {
* - Retorna HTML de la imagen o cadena vacía (sin placeholder)
*
* Tamaños disponibles:
* - apus-featured-large: 1200x600 (para single posts)
* - apus-featured-medium: 800x400 (para archives)
* - apus-thumbnail: 400x300 (para widgets/sidebars)
* - roi-featured-large: 1200x600 (para single posts)
* - roi-featured-medium: 800x400 (para archives)
* - roi-thumbnail: 400x300 (para widgets/sidebars)
*
* @param int|null $post_id ID del post (null = post actual)
* @param string $size Tamaño de imagen registrado (default: apus-featured-large)
* @param string $size Tamaño de imagen registrado (default: roi-featured-large)
* @param array $attr Atributos HTML adicionales para la imagen
* @param bool $force_show Forzar mostrar ignorando configuración (default: false)
* @return string HTML de la imagen o cadena vacía
*/
function apus_get_featured_image($post_id = null, $size = 'apus-featured-large', $attr = array(), $force_show = false) {
function roi_get_featured_image($post_id = null, $size = 'roi-featured-large', $attr = array(), $force_show = false) {
// Obtener ID del post actual si no se especifica
if (!$post_id) {
$post_id = get_the_ID();
@@ -55,18 +55,18 @@ function apus_get_featured_image($post_id = null, $size = 'apus-featured-large',
// Verificar configuración global según tipo de contenido
if (!$force_show) {
// Primero intentar con apus_get_option (sistema de opciones del tema)
if (function_exists('apus_get_option')) {
// Primero intentar con roi_get_option (sistema de opciones del tema)
if (function_exists('roi_get_option')) {
if ($post_type === 'post') {
$enabled = apus_get_option('featured_image_single', true);
$enabled = roi_get_option('featured_image_single', true);
} elseif ($post_type === 'page') {
$enabled = apus_get_option('featured_image_page', true);
$enabled = roi_get_option('featured_image_page', true);
} else {
$enabled = apus_get_option('featured_image_' . $post_type, true);
$enabled = roi_get_option('featured_image_' . $post_type, true);
}
} else {
// Fallback a theme_mod
$option_key = 'apus_featured_image_' . $post_type;
$option_key = 'roi_featured_image_' . $post_type;
$enabled = get_theme_mod($option_key, true);
}
@@ -106,19 +106,19 @@ function apus_get_featured_image($post_id = null, $size = 'apus-featured-large',
* Muestra la imagen destacada de un post
*
* Template tag para usar directamente en templates.
* Echo wrapper de apus_get_featured_image().
* Echo wrapper de roi_get_featured_image().
*
* Uso en templates:
* <?php apus_the_featured_image(); ?>
* <?php apus_the_featured_image(null, 'apus-featured-medium'); ?>
* <?php roi_the_featured_image(); ?>
* <?php roi_the_featured_image(null, 'roi-featured-medium'); ?>
*
* @param int|null $post_id ID del post (null = post actual)
* @param string $size Tamaño de imagen registrado
* @param array $attr Atributos HTML adicionales
* @param bool $force_show Forzar mostrar ignorando configuración
*/
function apus_the_featured_image($post_id = null, $size = 'apus-featured-large', $attr = array(), $force_show = false) {
echo apus_get_featured_image($post_id, $size, $attr, $force_show);
function roi_the_featured_image($post_id = null, $size = 'roi-featured-large', $attr = array(), $force_show = false) {
echo roi_get_featured_image($post_id, $size, $attr, $force_show);
}
/**
@@ -131,7 +131,7 @@ function apus_the_featured_image($post_id = null, $size = 'apus-featured-large',
* @param bool $with_link Envolver en enlace al post (default: true)
* @return string HTML del thumbnail o cadena vacía
*/
function apus_get_post_thumbnail($post_id = null, $with_link = true) {
function roi_get_post_thumbnail($post_id = null, $with_link = true) {
// Obtener ID del post actual si no se especifica
if (!$post_id) {
$post_id = get_the_ID();
@@ -148,7 +148,7 @@ function apus_get_post_thumbnail($post_id = null, $with_link = true) {
}
// Obtener la imagen con clases Bootstrap
$image = get_the_post_thumbnail($post_id, 'apus-featured-medium', array(
$image = get_the_post_thumbnail($post_id, 'roi-featured-medium', array(
'class' => 'img-fluid post-thumbnail',
'loading' => 'lazy',
'alt' => get_the_title($post_id)
@@ -179,30 +179,30 @@ function apus_get_post_thumbnail($post_id = null, $with_link = true) {
* Muestra el thumbnail del post para archives
*
* Template tag para usar directamente en template-parts.
* Echo wrapper de apus_get_post_thumbnail().
* Echo wrapper de roi_get_post_thumbnail().
*
* Uso en templates:
* <?php apus_the_post_thumbnail(); ?>
* <?php apus_the_post_thumbnail(null, false); // sin link ?>
* <?php roi_the_post_thumbnail(); ?>
* <?php roi_the_post_thumbnail(null, false); // sin link ?>
*
* @param int|null $post_id ID del post (null = post actual)
* @param bool $with_link Envolver en enlace al post
*/
function apus_the_post_thumbnail($post_id = null, $with_link = true) {
echo apus_get_post_thumbnail($post_id, $with_link);
function roi_the_post_thumbnail($post_id = null, $with_link = true) {
echo roi_get_post_thumbnail($post_id, $with_link);
}
/**
* Obtiene HTML de thumbnail pequeño para widgets/sidebars
*
* Versión mini para listados compactos en sidebars.
* Usa el tamaño apus-thumbnail (400x300).
* Usa el tamaño roi-thumbnail (400x300).
*
* @param int|null $post_id ID del post (null = post actual)
* @param bool $with_link Envolver en enlace al post (default: true)
* @return string HTML del thumbnail o cadena vacía
*/
function apus_get_post_thumbnail_small($post_id = null, $with_link = true) {
function roi_get_post_thumbnail_small($post_id = null, $with_link = true) {
// Obtener ID del post actual si no se especifica
if (!$post_id) {
$post_id = get_the_ID();
@@ -219,7 +219,7 @@ function apus_get_post_thumbnail_small($post_id = null, $with_link = true) {
}
// Obtener la imagen
$image = get_the_post_thumbnail($post_id, 'apus-thumbnail', array(
$image = get_the_post_thumbnail($post_id, 'roi-thumbnail', array(
'class' => 'img-fluid post-thumbnail-small',
'loading' => 'lazy',
'alt' => get_the_title($post_id)
@@ -250,13 +250,13 @@ function apus_get_post_thumbnail_small($post_id = null, $with_link = true) {
* Muestra el thumbnail pequeño del post
*
* Template tag para usar en widgets y sidebars.
* Echo wrapper de apus_get_post_thumbnail_small().
* Echo wrapper de roi_get_post_thumbnail_small().
*
* @param int|null $post_id ID del post (null = post actual)
* @param bool $with_link Envolver en enlace al post
*/
function apus_the_post_thumbnail_small($post_id = null, $with_link = true) {
echo apus_get_post_thumbnail_small($post_id, $with_link);
function roi_the_post_thumbnail_small($post_id = null, $with_link = true) {
echo roi_get_post_thumbnail_small($post_id, $with_link);
}
/**
@@ -266,14 +266,14 @@ function apus_the_post_thumbnail_small($post_id = null, $with_link = true) {
* Útil para estructuras if/else en templates.
*
* Uso en templates:
* <?php if (apus_should_show_featured_image()): ?>
* <?php if (roi_should_show_featured_image()): ?>
* <div class="has-thumbnail">...</div>
* <?php endif; ?>
*
* @param int|null $post_id ID del post (null = post actual)
* @return bool True si debe mostrarse, false en caso contrario
*/
function apus_should_show_featured_image($post_id = null) {
function roi_should_show_featured_image($post_id = null) {
// Obtener ID del post actual si no se especifica
if (!$post_id) {
$post_id = get_the_ID();
@@ -293,17 +293,17 @@ function apus_should_show_featured_image($post_id = null) {
$post_type = get_post_type($post_id);
// Verificar configuración global según tipo de contenido
if (function_exists('apus_get_option')) {
if (function_exists('roi_get_option')) {
if ($post_type === 'post') {
$enabled = apus_get_option('featured_image_single', true);
$enabled = roi_get_option('featured_image_single', true);
} elseif ($post_type === 'page') {
$enabled = apus_get_option('featured_image_page', true);
$enabled = roi_get_option('featured_image_page', true);
} else {
$enabled = apus_get_option('featured_image_' . $post_type, true);
$enabled = roi_get_option('featured_image_' . $post_type, true);
}
} else {
// Fallback a theme_mod
$option_key = 'apus_featured_image_' . $post_type;
$option_key = 'roi_featured_image_' . $post_type;
$enabled = get_theme_mod($option_key, true);
}
@@ -316,14 +316,14 @@ function apus_should_show_featured_image($post_id = null) {
* Útil para backgrounds CSS o meta tags de redes sociales (Open Graph, Twitter Cards).
*
* Uso:
* $image_url = apus_get_featured_image_url();
* $image_url = roi_get_featured_image_url();
* echo '<div style="background-image: url(' . $image_url . ')"></div>';
*
* @param int|null $post_id ID del post (null = post actual)
* @param string $size Tamaño de imagen registrado (default: apus-featured-large)
* @param string $size Tamaño de imagen registrado (default: roi-featured-large)
* @return string URL de la imagen o cadena vacía
*/
function apus_get_featured_image_url($post_id = null, $size = 'apus-featured-large') {
function roi_get_featured_image_url($post_id = null, $size = 'roi-featured-large') {
// Obtener ID del post actual si no se especifica
if (!$post_id) {
$post_id = get_the_ID();
@@ -352,17 +352,17 @@ function apus_get_featured_image_url($post_id = null, $size = 'apus-featured-lar
* Evita layout shift (CLS) con ratio predefinido usando Bootstrap ratio utility.
*
* Uso en templates:
* <?php echo apus_get_featured_image_responsive(); ?>
* <?php echo apus_get_featured_image_responsive(null, 'apus-featured-medium', '16/9'); ?>
* <?php echo roi_get_featured_image_responsive(); ?>
* <?php echo roi_get_featured_image_responsive(null, 'roi-featured-medium', '16/9'); ?>
*
* @param int|null $post_id ID del post (null = post actual)
* @param string $size Tamaño de imagen registrado (default: apus-featured-large)
* @param string $size Tamaño de imagen registrado (default: roi-featured-large)
* @param string $aspect_ratio Ratio CSS - '2/1' para 2:1, '16/9', etc. (default: '2/1')
* @return string HTML del contenedor con imagen o cadena vacía
*/
function apus_get_featured_image_responsive($post_id = null, $size = 'apus-featured-large', $aspect_ratio = '2/1') {
function roi_get_featured_image_responsive($post_id = null, $size = 'roi-featured-large', $aspect_ratio = '2/1') {
// Obtener la imagen
$image = apus_get_featured_image($post_id, $size);
$image = roi_get_featured_image($post_id, $size);
// Si no hay imagen, retornar vacío
if (empty($image)) {
@@ -381,14 +381,14 @@ function apus_get_featured_image_responsive($post_id = null, $size = 'apus-featu
* Muestra el contenedor responsive de imagen destacada
*
* Template tag para usar directamente en templates.
* Echo wrapper de apus_get_featured_image_responsive().
* Echo wrapper de roi_get_featured_image_responsive().
*
* @param int|null $post_id ID del post (null = post actual)
* @param string $size Tamaño de imagen registrado
* @param string $aspect_ratio Ratio CSS (ej: '16/9', '2/1')
*/
function apus_the_featured_image_responsive($post_id = null, $size = 'apus-featured-large', $aspect_ratio = '2/1') {
echo apus_get_featured_image_responsive($post_id, $size, $aspect_ratio);
function roi_the_featured_image_responsive($post_id = null, $size = 'roi-featured-large', $aspect_ratio = '2/1') {
echo roi_get_featured_image_responsive($post_id, $size, $aspect_ratio);
}
/**
@@ -399,7 +399,7 @@ function apus_the_featured_image_responsive($post_id = null, $size = 'apus-featu
* @param string $post_type Tipo de post (vacío = post actual)
* @return bool True si habilitadas, false en caso contrario
*/
function apus_is_featured_image_enabled($post_type = '') {
function roi_is_featured_image_enabled($post_type = '') {
if (empty($post_type)) {
$post_type = get_post_type();
}
@@ -408,19 +408,19 @@ function apus_is_featured_image_enabled($post_type = '') {
return true; // Default habilitado
}
// Intentar con apus_get_option primero
if (function_exists('apus_get_option')) {
// Intentar con roi_get_option primero
if (function_exists('roi_get_option')) {
if ($post_type === 'post') {
return apus_get_option('featured_image_single', true);
return roi_get_option('featured_image_single', true);
} elseif ($post_type === 'page') {
return apus_get_option('featured_image_page', true);
return roi_get_option('featured_image_page', true);
} else {
return apus_get_option('featured_image_' . $post_type, true);
return roi_get_option('featured_image_' . $post_type, true);
}
}
// Fallback a theme_mod
$option_key = 'apus_featured_image_' . $post_type;
$option_key = 'roi_featured_image_' . $post_type;
return (bool) get_theme_mod($option_key, true);
}
@@ -432,16 +432,16 @@ function apus_is_featured_image_enabled($post_type = '') {
*
* @param WP_Customize_Manager $wp_customize Objeto Theme Customizer
*/
function apus_featured_image_customizer($wp_customize) {
function roi_featured_image_customizer($wp_customize) {
// Solo agregar si no existe el panel de opciones del tema
if (function_exists('apus_get_option')) {
if (function_exists('roi_get_option')) {
return; // El panel de opciones manejará esto
}
// Agregar sección
$wp_customize->add_section('apus_featured_images', array(
'title' => __('Imágenes Destacadas', 'apus-theme'),
'description' => __('Configurar visualización de imágenes destacadas por tipo de contenido.', 'apus-theme'),
$wp_customize->add_section('roi_featured_images', array(
'title' => __('Imágenes Destacadas', 'roi-theme'),
'description' => __('Configurar visualización de imágenes destacadas por tipo de contenido.', 'roi-theme'),
'priority' => 30,
));
@@ -454,7 +454,7 @@ function apus_featured_image_customizer($wp_customize) {
continue;
}
$setting_id = 'apus_featured_image_' . $post_type->name;
$setting_id = 'roi_featured_image_' . $post_type->name;
// Agregar setting
$wp_customize->add_setting($setting_id, array(
@@ -467,12 +467,12 @@ function apus_featured_image_customizer($wp_customize) {
$wp_customize->add_control($setting_id, array(
'label' => sprintf(
/* translators: %s: nombre del tipo de post */
__('Habilitar para %s', 'apus-theme'),
__('Habilitar para %s', 'roi-theme'),
$post_type->labels->name
),
'section' => 'apus_featured_images',
'section' => 'roi_featured_images',
'type' => 'checkbox',
));
}
}
add_action('customize_register', 'apus_featured_image_customizer');
add_action('customize_register', 'roi_featured_image_customizer');