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

@@ -12,7 +12,7 @@
* 2. Main stylesheet is loaded asynchronously after page load
* 3. Improves Core Web Vitals by reducing render-blocking CSS
*
* @package Apus_Theme
* @package ROI_Theme
* @since 1.0.0
*/
@@ -27,8 +27,8 @@ if ( ! defined( 'ABSPATH' ) ) {
* @since 1.0.0
* @return bool
*/
function apus_is_critical_css_enabled() {
return get_theme_mod( 'apus_enable_critical_css', false );
function roi_is_critical_css_enabled() {
return get_theme_mod( 'roi_enable_critical_css', false );
}
/**
@@ -40,12 +40,12 @@ function apus_is_critical_css_enabled() {
* @since 1.0.0
* @return string Critical CSS content
*/
function apus_get_critical_css() {
function roi_get_critical_css() {
// Define critical CSS based on page type
$critical_css = '';
// Get transient to cache critical CSS
$transient_key = 'apus_critical_css_' . apus_get_page_type();
$transient_key = 'roi_critical_css_' . roi_get_page_type();
$cached_css = get_transient( $transient_key );
if ( false !== $cached_css ) {
@@ -54,13 +54,13 @@ function apus_get_critical_css() {
// Generate critical CSS based on page type
if ( is_front_page() || is_home() ) {
$critical_css = apus_get_home_critical_css();
$critical_css = roi_get_home_critical_css();
} elseif ( is_single() ) {
$critical_css = apus_get_single_critical_css();
$critical_css = roi_get_single_critical_css();
} elseif ( is_archive() || is_category() || is_tag() ) {
$critical_css = apus_get_archive_critical_css();
$critical_css = roi_get_archive_critical_css();
} else {
$critical_css = apus_get_default_critical_css();
$critical_css = roi_get_default_critical_css();
}
// Cache for 24 hours
@@ -75,7 +75,7 @@ function apus_get_critical_css() {
* @since 1.0.0
* @return string Page type identifier
*/
function apus_get_page_type() {
function roi_get_page_type() {
if ( is_front_page() ) {
return 'home';
} elseif ( is_single() ) {
@@ -97,7 +97,7 @@ function apus_get_page_type() {
* @since 1.0.0
* @return string
*/
function apus_get_home_critical_css() {
function roi_get_home_critical_css() {
return '
/* Reset and Base */
*,*::before,*::after{box-sizing:border-box}
@@ -136,7 +136,7 @@ function apus_get_home_critical_css() {
* @since 1.0.0
* @return string
*/
function apus_get_single_critical_css() {
function roi_get_single_critical_css() {
return '
/* Reset and Base */
*,*::before,*::after{box-sizing:border-box}
@@ -175,7 +175,7 @@ function apus_get_single_critical_css() {
* @since 1.0.0
* @return string
*/
function apus_get_archive_critical_css() {
function roi_get_archive_critical_css() {
return '
/* Reset and Base */
*,*::before,*::after{box-sizing:border-box}
@@ -211,7 +211,7 @@ function apus_get_archive_critical_css() {
* @since 1.0.0
* @return string
*/
function apus_get_default_critical_css() {
function roi_get_default_critical_css() {
return '
/* Reset and Base */
*,*::before,*::after{box-sizing:border-box}
@@ -240,12 +240,12 @@ function apus_get_default_critical_css() {
*
* @since 1.0.0
*/
function apus_output_critical_css() {
if ( ! apus_is_critical_css_enabled() ) {
function roi_output_critical_css() {
if ( ! roi_is_critical_css_enabled() ) {
return;
}
$critical_css = apus_get_critical_css();
$critical_css = roi_get_critical_css();
if ( empty( $critical_css ) ) {
return;
@@ -256,36 +256,36 @@ function apus_output_critical_css() {
$critical_css = trim( $critical_css );
// Output inline critical CSS
echo '<style id="apus-critical-css">' . $critical_css . '</style>' . "\n";
echo '<style id="roi-critical-css">' . $critical_css . '</style>' . "\n";
}
add_action( 'wp_head', 'apus_output_critical_css', 1 );
add_action( 'wp_head', 'roi_output_critical_css', 1 );
/**
* Load main stylesheet asynchronously when critical CSS is enabled
*
* @since 1.0.0
*/
function apus_async_main_stylesheet() {
if ( ! apus_is_critical_css_enabled() ) {
function roi_async_main_stylesheet() {
if ( ! roi_is_critical_css_enabled() ) {
return;
}
// Dequeue main stylesheet to prevent render-blocking
wp_dequeue_style( 'apus-theme-style' );
wp_dequeue_style( 'roi-theme-style' );
// Enqueue with media="print" and onload to load asynchronously
wp_enqueue_style(
'apus-theme-style-async',
'roi-theme-style-async',
get_stylesheet_uri(),
array(),
APUS_VERSION,
ROI_VERSION,
'print'
);
// Add onload attribute to switch media to "all"
add_filter( 'style_loader_tag', 'apus_add_async_attribute', 10, 2 );
add_filter( 'style_loader_tag', 'roi_add_async_attribute', 10, 2 );
}
add_action( 'wp_enqueue_scripts', 'apus_async_main_stylesheet', 999 );
add_action( 'wp_enqueue_scripts', 'roi_async_main_stylesheet', 999 );
/**
* Add async loading attributes to stylesheet
@@ -295,8 +295,8 @@ add_action( 'wp_enqueue_scripts', 'apus_async_main_stylesheet', 999 );
* @param string $handle The style's registered handle.
* @return string Modified link tag
*/
function apus_add_async_attribute( $html, $handle ) {
if ( 'apus-theme-style-async' !== $handle ) {
function roi_add_async_attribute( $html, $handle ) {
if ( 'roi-theme-style-async' !== $handle ) {
return $html;
}
@@ -319,49 +319,49 @@ function apus_add_async_attribute( $html, $handle ) {
* @since 1.0.0
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
function apus_critical_css_customizer( $wp_customize ) {
function roi_critical_css_customizer( $wp_customize ) {
// Add Performance section
$wp_customize->add_section(
'apus_performance',
'roi_performance',
array(
'title' => __( 'Performance Optimization', 'apus-theme' ),
'title' => __( 'Performance Optimization', 'roi-theme' ),
'priority' => 130,
)
);
// Critical CSS Enable/Disable
$wp_customize->add_setting(
'apus_enable_critical_css',
'roi_enable_critical_css',
array(
'default' => false,
'sanitize_callback' => 'apus_sanitize_checkbox',
'sanitize_callback' => 'roi_sanitize_checkbox',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'apus_enable_critical_css',
'roi_enable_critical_css',
array(
'label' => __( 'Enable Critical CSS', 'apus-theme' ),
'description' => __( 'Inline critical CSS and load main stylesheet asynchronously. This can improve Core Web Vitals but may cause a flash of unstyled content (FOUC). Test thoroughly before enabling in production.', 'apus-theme' ),
'section' => 'apus_performance',
'label' => __( 'Enable Critical CSS', 'roi-theme' ),
'description' => __( 'Inline critical CSS and load main stylesheet asynchronously. This can improve Core Web Vitals but may cause a flash of unstyled content (FOUC). Test thoroughly before enabling in production.', 'roi-theme' ),
'section' => 'roi_performance',
'type' => 'checkbox',
)
);
}
add_action( 'customize_register', 'apus_critical_css_customizer' );
add_action( 'customize_register', 'roi_critical_css_customizer' );
/**
* Clear critical CSS cache when theme is updated
*
* @since 1.0.0
*/
function apus_clear_critical_css_cache() {
function roi_clear_critical_css_cache() {
$page_types = array( 'home', 'single', 'archive', 'search', '404', 'page' );
foreach ( $page_types as $type ) {
delete_transient( 'apus_critical_css_' . $type );
delete_transient( 'roi_critical_css_' . $type );
}
}
add_action( 'after_switch_theme', 'apus_clear_critical_css_cache' );
add_action( 'customize_save_after', 'apus_clear_critical_css_cache' );
add_action( 'after_switch_theme', 'roi_clear_critical_css_cache' );
add_action( 'customize_save_after', 'roi_clear_critical_css_cache' );