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

@@ -2,7 +2,7 @@
/**
* Theme Options Admin Page
*
* @package Apus_Theme
* @package ROI_Theme
* @since 1.0.0
*/
@@ -16,26 +16,26 @@ if (!defined('ABSPATH')) {
* DESACTIVADO: Ahora se usa el nuevo Admin Panel en admin/includes/class-admin-menu.php
*/
/*
function apus_add_admin_menu() {
function roi_add_admin_menu() {
add_theme_page(
__('Apus Theme Options', 'apus-theme'), // Page title
__('Theme Options', 'apus-theme'), // Menu title
__('ROI Theme Options', 'roi-theme'), // Page title
__('Theme Options', 'roi-theme'), // Menu title
'manage_options', // Capability
'apus-theme-options', // Menu slug
'apus_render_options_page', // Callback function
'roi-theme-options', // Menu slug
'roi_render_options_page', // Callback function
30 // Position
);
}
add_action('admin_menu', 'apus_add_admin_menu');
add_action('admin_menu', 'roi_add_admin_menu');
*/
/**
* Render the options page
*/
function apus_render_options_page() {
function roi_render_options_page() {
// Check user capabilities
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'apus-theme'));
wp_die(__('You do not have sufficient permissions to access this page.', 'roi-theme'));
}
// Load the template
@@ -45,9 +45,9 @@ function apus_render_options_page() {
/**
* Enqueue admin scripts and styles
*/
function apus_enqueue_admin_scripts($hook) {
function roi_enqueue_admin_scripts($hook) {
// Only load on our theme options page
if ($hook !== 'appearance_page_apus-theme-options') {
if ($hook !== 'appearance_page_roi-theme-options') {
return;
}
@@ -56,119 +56,119 @@ function apus_enqueue_admin_scripts($hook) {
// Enqueue admin styles
wp_enqueue_style(
'apus-admin-options',
'roiadmin-options',
get_template_directory_uri() . '/admin/assets/css/theme-options.css',
array(),
APUS_VERSION
ROI_VERSION
);
// Enqueue admin scripts
wp_enqueue_script(
'apus-admin-options',
'roiadmin-options',
get_template_directory_uri() . '/admin/assets/js/theme-options.js',
array('jquery', 'wp-color-picker'),
APUS_VERSION,
ROI_VERSION,
true
);
// Localize script
wp_localize_script('apus-admin-options', 'apusAdminOptions', array(
wp_localize_script('roiadmin-options', 'rroiminOptions', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('apus_admin_nonce'),
'nonce' => wp_create_nonce('roi_admin_nonce'),
'strings' => array(
'selectImage' => __('Select Image', 'apus-theme'),
'useImage' => __('Use Image', 'apus-theme'),
'removeImage' => __('Remove Image', 'apus-theme'),
'confirmReset' => __('Are you sure you want to reset all options to default values? This cannot be undone.', 'apus-theme'),
'saved' => __('Settings saved successfully!', 'apus-theme'),
'error' => __('An error occurred while saving settings.', 'apus-theme'),
'selectImage' => __('Select Image', 'roi-theme'),
'useImage' => __('Use Image', 'roi-theme'),
'removeImage' => __('Remove Image', 'roi-theme'),
'confirmReset' => __('Are you sure you want to reset all options to default values? This cannot be undone.', 'roi-theme'),
'saved' => __('Settings saved successfully!', 'roi-theme'),
'error' => __('An error occurred while saving settings.', 'roi-theme'),
),
));
}
add_action('admin_enqueue_scripts', 'apus_enqueue_admin_scripts');
add_action('admin_enqueue_scripts', 'roi_enqueue_admin_scripts');
/**
* Add settings link to theme actions
*/
function apus_add_settings_link($links) {
$settings_link = '<a href="' . admin_url('themes.php?page=apus-theme-options') . '">' . __('Settings', 'apus-theme') . '</a>';
function roi_add_settings_link($links) {
$settings_link = '<a href="' . admin_url('themes.php?page=roi-theme-options') . '">' . __('Settings', 'roi-theme') . '</a>';
array_unshift($links, $settings_link);
return $links;
}
add_filter('theme_action_links_' . get_template(), 'apus_add_settings_link');
add_filter('theme_action_links_' . get_template(), 'roi_add_settings_link');
/**
* AJAX handler for resetting options
*/
function apus_reset_options_ajax() {
check_ajax_referer('apus_admin_nonce', 'nonce');
function roi_reset_options_ajax() {
check_ajax_referer('roi_admin_nonce', 'nonce');
if (!current_user_can('manage_options')) {
wp_send_json_error(array('message' => __('Insufficient permissions.', 'apus-theme')));
wp_send_json_error(array('message' => __('Insufficient permissions.', 'roi-theme')));
}
// Delete options to reset to defaults
delete_option('apus_theme_options');
delete_option('roi_theme_options');
wp_send_json_success(array('message' => __('Options reset to defaults successfully.', 'apus-theme')));
wp_send_json_success(array('message' => __('Options reset to defaults successfully.', 'roi-theme')));
}
add_action('wp_ajax_apus_reset_options', 'apus_reset_options_ajax');
add_action('wp_ajax_roi_reset_options', 'roi_reset_options_ajax');
/**
* AJAX handler for exporting options
*/
function apus_export_options_ajax() {
check_ajax_referer('apus_admin_nonce', 'nonce');
function roi_export_options_ajax() {
check_ajax_referer('roi_admin_nonce', 'nonce');
if (!current_user_can('manage_options')) {
wp_send_json_error(array('message' => __('Insufficient permissions.', 'apus-theme')));
wp_send_json_error(array('message' => __('Insufficient permissions.', 'roi-theme')));
}
$options = get_option('apus_theme_options', array());
$options = get_option('roi_theme_options', array());
wp_send_json_success(array(
'data' => json_encode($options, JSON_PRETTY_PRINT),
'filename' => 'apus-theme-options-' . date('Y-m-d') . '.json'
'filename' => 'roi-theme-options-' . date('Y-m-d') . '.json'
));
}
add_action('wp_ajax_apus_export_options', 'apus_export_options_ajax');
add_action('wp_ajax_roi_export_options', 'roi_export_options_ajax');
/**
* AJAX handler for importing options
*/
function apus_import_options_ajax() {
check_ajax_referer('apus_admin_nonce', 'nonce');
function roi_import_options_ajax() {
check_ajax_referer('roi_admin_nonce', 'nonce');
if (!current_user_can('manage_options')) {
wp_send_json_error(array('message' => __('Insufficient permissions.', 'apus-theme')));
wp_send_json_error(array('message' => __('Insufficient permissions.', 'roi-theme')));
}
if (!isset($_POST['import_data'])) {
wp_send_json_error(array('message' => __('No import data provided.', 'apus-theme')));
wp_send_json_error(array('message' => __('No import data provided.', 'roi-theme')));
}
$import_data = json_decode(stripslashes($_POST['import_data']), true);
if (json_last_error() !== JSON_ERROR_NONE) {
wp_send_json_error(array('message' => __('Invalid JSON data.', 'apus-theme')));
wp_send_json_error(array('message' => __('Invalid JSON data.', 'roi-theme')));
}
// Sanitize imported data
$sanitized_data = apus_sanitize_options($import_data);
$sanitized_data = roi_sanitize_options($import_data);
// Update options
update_option('apus_theme_options', $sanitized_data);
update_option('roi_theme_options', $sanitized_data);
wp_send_json_success(array('message' => __('Options imported successfully.', 'apus-theme')));
wp_send_json_success(array('message' => __('Options imported successfully.', 'roi-theme')));
}
add_action('wp_ajax_apus_import_options', 'apus_import_options_ajax');
add_action('wp_ajax_roi_import_options', 'roi_import_options_ajax');
/**
* Add admin notices
*/
function apus_admin_notices() {
function roi_admin_notices() {
$screen = get_current_screen();
if ($screen->id !== 'appearance_page_apus-theme-options') {
if ($screen->id !== 'appearance_page_roi-theme-options') {
return;
}
@@ -176,42 +176,42 @@ function apus_admin_notices() {
if (isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true') {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e('Settings saved successfully!', 'apus-theme'); ?></p>
<p><?php _e('Settings saved successfully!', 'roi-theme'); ?></p>
</div>
<?php
}
}
add_action('admin_notices', 'apus_admin_notices');
add_action('admin_notices', 'roi_admin_notices');
/**
* Register theme options in Customizer as well (for preview)
*/
function apus_customize_register($wp_customize) {
function roi_customize_register($wp_customize) {
// Add a panel for theme options
$wp_customize->add_panel('apus_theme_options', array(
'title' => __('Apus Theme Options', 'apus-theme'),
'description' => __('Configure theme options (Also available in Theme Options page)', 'apus-theme'),
$wp_customize->add_panel('roi_theme_options', array(
'title' => __('ROI Theme Options', 'roi-theme'),
'description' => __('Configure theme options (Also available in Theme Options page)', 'roi-theme'),
'priority' => 10,
));
// General Section
$wp_customize->add_section('apus_general', array(
'title' => __('General Settings', 'apus-theme'),
'panel' => 'apus_theme_options',
$wp_customize->add_section('roi_general', array(
'title' => __('General Settings', 'roi-theme'),
'panel' => 'roi_theme_options',
'priority' => 10,
));
// Enable breadcrumbs
$wp_customize->add_setting('apus_theme_options[enable_breadcrumbs]', array(
$wp_customize->add_setting('roi_theme_options[enable_breadcrumbs]', array(
'default' => true,
'type' => 'option',
'sanitize_callback' => 'apus_sanitize_checkbox',
'sanitize_callback' => 'roi_sanitize_checkbox',
));
$wp_customize->add_control('apus_theme_options[enable_breadcrumbs]', array(
'label' => __('Enable Breadcrumbs', 'apus-theme'),
'section' => 'apus_general',
$wp_customize->add_control('roi_theme_options[enable_breadcrumbs]', array(
'label' => __('Enable Breadcrumbs', 'roi-theme'),
'section' => 'roi_general',
'type' => 'checkbox',
));
}
add_action('customize_register', 'apus_customize_register');
add_action('customize_register', 'roi_customize_register');