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>
157 lines
3.5 KiB
PHP
157 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Settings Manager Class
|
|
*
|
|
* CRUD de configuraciones por componentes
|
|
*
|
|
* @package ROI_Theme
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class ROI_Settings_Manager {
|
|
|
|
const OPTION_NAME = 'roi_theme_settings';
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
add_action('wp_ajax_roi_get_settings', array($this, 'ajax_get_settings'));
|
|
add_action('wp_ajax_roi_save_settings', array($this, 'ajax_save_settings'));
|
|
}
|
|
|
|
/**
|
|
* Obtener configuraciones
|
|
*/
|
|
public function get_settings() {
|
|
$settings = get_option(self::OPTION_NAME, array());
|
|
$defaults = $this->get_defaults();
|
|
|
|
return wp_parse_args($settings, $defaults);
|
|
}
|
|
|
|
/**
|
|
* Guardar configuraciones
|
|
*/
|
|
public function save_settings($data) {
|
|
// Validar
|
|
$validator = new ROI_Validator();
|
|
$validation = $validator->validate($data);
|
|
|
|
if (!$validation['valid']) {
|
|
return array(
|
|
'success' => false,
|
|
'message' => 'Error de validación',
|
|
'errors' => $validation['errors']
|
|
);
|
|
}
|
|
|
|
// Sanitizar
|
|
$sanitized = $this->sanitize_settings($data);
|
|
|
|
// Agregar metadata
|
|
$sanitized['version'] = ROI_ADMIN_PANEL_VERSION;
|
|
$sanitized['updated_at'] = current_time('mysql');
|
|
|
|
// Guardar
|
|
update_option(self::OPTION_NAME, $sanitized, false);
|
|
|
|
return array(
|
|
'success' => true,
|
|
'message' => 'Configuración guardada correctamente'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Valores por defecto
|
|
* Lee los defaults desde la tabla wp_roi_theme_components_defaults
|
|
*/
|
|
public function get_defaults() {
|
|
$db_manager = new ROI_DB_Manager();
|
|
$component_names = $db_manager->list_components('defaults');
|
|
|
|
$defaults = array(
|
|
'version' => ROI_ADMIN_PANEL_VERSION,
|
|
'components' => array()
|
|
);
|
|
|
|
// Obtener configuraciones de cada componente desde la tabla de defaults
|
|
foreach ($component_names as $component_name) {
|
|
$defaults['components'][$component_name] = $db_manager->get_config($component_name, null, 'defaults');
|
|
}
|
|
|
|
return $defaults;
|
|
}
|
|
|
|
/**
|
|
* Sanitizar configuraciones
|
|
* NOTA: Los sanitizers de componentes se ejecutarán aquí cuando se implementen
|
|
*/
|
|
public function sanitize_settings($data) {
|
|
$sanitized = array(
|
|
'components' => array()
|
|
);
|
|
|
|
// Los componentes se sanitizarán aquí cuando se ejecute el algoritmo
|
|
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* AJAX: Obtener configuraciones
|
|
*/
|
|
public function ajax_get_settings() {
|
|
// Verificar nonce usando check_ajax_referer (método recomendado para AJAX)
|
|
check_ajax_referer('roi_admin_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error('Permisos insuficientes');
|
|
}
|
|
|
|
$settings = $this->get_settings();
|
|
wp_send_json_success($settings);
|
|
}
|
|
|
|
/**
|
|
* AJAX: Guardar configuraciones
|
|
*/
|
|
public function ajax_save_settings() {
|
|
// Verificar nonce usando check_ajax_referer (método recomendado para AJAX)
|
|
check_ajax_referer('roi_admin_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error('Permisos insuficientes');
|
|
}
|
|
|
|
// Los datos vienen como JSON string en $_POST['components']
|
|
if (!isset($_POST['components'])) {
|
|
wp_send_json_error('Datos inválidos - falta components');
|
|
}
|
|
|
|
$components = json_decode(stripslashes($_POST['components']), true);
|
|
|
|
if (!is_array($components)) {
|
|
wp_send_json_error('Datos inválidos - components no es un array válido');
|
|
}
|
|
|
|
$data = array(
|
|
'components' => $components
|
|
);
|
|
|
|
$result = $this->save_settings($data);
|
|
|
|
if ($result['success']) {
|
|
wp_send_json_success($result);
|
|
} else {
|
|
wp_send_json_error($result);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Instanciar clase
|
|
new ROI_Settings_Manager();
|