177 lines
5.8 KiB
PHP
Executable File
177 lines
5.8 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Script di controllo compatibilità layout NetGescon
|
|
* Controlla tutte le viste Blade per problemi di layout
|
|
*
|
|
* @author Michele Barone
|
|
* @date 27/07/2025
|
|
*/
|
|
|
|
echo "🔍 NetGescon Layout Compatibility Checker\n";
|
|
echo "==========================================\n\n";
|
|
|
|
$basePath = '/var/www/netgescon/resources/views';
|
|
$problems = [];
|
|
$totalFiles = 0;
|
|
$problemFiles = 0;
|
|
|
|
/**
|
|
* Cerca ricorsivamente i file blade
|
|
*/
|
|
function findBladeFiles($dir)
|
|
{
|
|
$files = [];
|
|
$iterator = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS)
|
|
);
|
|
|
|
foreach ($iterator as $file) {
|
|
if ($file->getExtension() === 'php' && strpos($file->getFilename(), '.blade.') !== false) {
|
|
$files[] = $file->getPathname();
|
|
}
|
|
}
|
|
|
|
return $files;
|
|
}
|
|
|
|
/**
|
|
* Controlla un singolo file per problemi di layout
|
|
*/
|
|
function checkFile($filePath)
|
|
{
|
|
$content = file_get_contents($filePath);
|
|
$issues = [];
|
|
|
|
// 1. Controlla x-app-layout (layout vecchio)
|
|
if (preg_match('/<x-app-layout[^>]*>/', $content)) {
|
|
$issues[] = [
|
|
'type' => 'LAYOUT_OBSOLETO',
|
|
'description' => 'Utilizza <x-app-layout> invece di @extends',
|
|
'severity' => 'HIGH',
|
|
'fix' => 'Sostituire con @extends(\'admin.layouts.app\')'
|
|
];
|
|
}
|
|
|
|
// 2. Controlla admin.layouts.main (layout inesistente)
|
|
if (preg_match('/@extends\([\'"]admin\.layouts\.main[\'"]/', $content)) {
|
|
$issues[] = [
|
|
'type' => 'LAYOUT_INESISTENTE',
|
|
'description' => 'Utilizza admin.layouts.main che non esiste',
|
|
'severity' => 'HIGH',
|
|
'fix' => 'Sostituire con @extends(\'admin.layouts.app\')'
|
|
];
|
|
}
|
|
|
|
// 3. Controlla classi Tailwind (potrebbero non funzionare)
|
|
if (preg_match_all('/class=["\']([^"\']*(?:bg-\w+-\d+|text-\w+-\d+|p-\d+|m-\d+|w-\d+|h-\d+)[^"\']*)["\']/', $content, $matches)) {
|
|
$tailwindClasses = array_unique($matches[1]);
|
|
if (count($tailwindClasses) > 5) { // Se trova molte classi Tailwind
|
|
$issues[] = [
|
|
'type' => 'TAILWIND_MISTO',
|
|
'description' => 'Contiene molte classi Tailwind, potrebbe non essere compatibile con Bootstrap',
|
|
'severity' => 'MEDIUM',
|
|
'fix' => 'Convertire le classi Tailwind a Bootstrap'
|
|
];
|
|
}
|
|
}
|
|
|
|
// 4. Controlla <x-slot> (componenti Blade specifici di Jetstream)
|
|
if (preg_match('/<x-slot[^>]*>/', $content)) {
|
|
$issues[] = [
|
|
'type' => 'COMPONENT_OBSOLETO',
|
|
'description' => 'Utilizza <x-slot> che potrebbe non funzionare',
|
|
'severity' => 'MEDIUM',
|
|
'fix' => 'Sostituire con sezioni Blade standard @section'
|
|
];
|
|
}
|
|
|
|
// 5. Controlla mancanza di @section('title')
|
|
if (!preg_match('/@section\([\'"]title[\'"]/', $content) && preg_match('/@extends/', $content)) {
|
|
$issues[] = [
|
|
'type' => 'TITLE_MANCANTE',
|
|
'description' => 'Manca @section(\'title\')',
|
|
'severity' => 'LOW',
|
|
'fix' => 'Aggiungere @section(\'title\', \'Titolo Pagina\')'
|
|
];
|
|
}
|
|
|
|
return $issues;
|
|
}
|
|
|
|
/**
|
|
* Colora l'output per la console
|
|
*/
|
|
function colorize($text, $color)
|
|
{
|
|
$colors = [
|
|
'red' => "\033[31m",
|
|
'green' => "\033[32m",
|
|
'yellow' => "\033[33m",
|
|
'blue' => "\033[34m",
|
|
'magenta' => "\033[35m",
|
|
'cyan' => "\033[36m",
|
|
'white' => "\033[37m",
|
|
'reset' => "\033[0m"
|
|
];
|
|
|
|
return $colors[$color] . $text . $colors['reset'];
|
|
}
|
|
|
|
// Trova tutti i file blade
|
|
$bladeFiles = findBladeFiles($basePath);
|
|
$totalFiles = count($bladeFiles);
|
|
|
|
echo "📁 Trovati " . colorize($totalFiles, 'blue') . " file .blade.php\n\n";
|
|
|
|
// Controlla ogni file
|
|
foreach ($bladeFiles as $file) {
|
|
$relativePath = str_replace($basePath . '/', '', $file);
|
|
$issues = checkFile($file);
|
|
|
|
if (!empty($issues)) {
|
|
$problemFiles++;
|
|
$problems[$relativePath] = $issues;
|
|
|
|
echo "❌ " . colorize($relativePath, 'red') . "\n";
|
|
foreach ($issues as $issue) {
|
|
$severityColor = $issue['severity'] === 'HIGH' ? 'red' : ($issue['severity'] === 'MEDIUM' ? 'yellow' : 'cyan');
|
|
echo " └─ " . colorize("[{$issue['severity']}]", $severityColor) . " {$issue['type']}: {$issue['description']}\n";
|
|
echo " 💡 Fix: " . colorize($issue['fix'], 'green') . "\n";
|
|
}
|
|
echo "\n";
|
|
}
|
|
}
|
|
|
|
// Riepilogo
|
|
echo "\n" . str_repeat("=", 50) . "\n";
|
|
echo "📊 " . colorize("RIEPILOGO CONTROLLO", 'magenta') . "\n";
|
|
echo str_repeat("=", 50) . "\n";
|
|
echo "📁 File totali controllati: " . colorize($totalFiles, 'blue') . "\n";
|
|
echo "❌ File con problemi: " . colorize($problemFiles, 'red') . "\n";
|
|
echo "✅ File compatibili: " . colorize(($totalFiles - $problemFiles), 'green') . "\n";
|
|
|
|
if ($problemFiles > 0) {
|
|
echo "\n🔧 " . colorize("AZIONI RACCOMANDATE:", 'yellow') . "\n";
|
|
echo "1. Sostituire tutti i <x-app-layout> con @extends('admin.layouts.app')\n";
|
|
echo "2. Convertire le classi Tailwind a Bootstrap\n";
|
|
echo "3. Aggiungere @section('title') mancanti\n";
|
|
echo "4. Testare ogni pagina dopo le modifiche\n";
|
|
} else {
|
|
echo "\n🎉 " . colorize("Tutti i file sono compatibili!", 'green') . "\n";
|
|
}
|
|
|
|
echo "\n📋 Per applicare le correzioni automatiche, eseguire:\n";
|
|
echo colorize("php fix-layout-compatibility.php", 'cyan') . "\n\n";
|
|
|
|
// Salva il report in JSON per eventuali tool automatici
|
|
$report = [
|
|
'timestamp' => date('Y-m-d H:i:s'),
|
|
'total_files' => $totalFiles,
|
|
'problem_files' => $problemFiles,
|
|
'problems' => $problems
|
|
];
|
|
|
|
file_put_contents('/var/www/netgescon/layout-compatibility-report.json', json_encode($report, JSON_PRETTY_PRINT));
|
|
echo "💾 Report salvato in: " . colorize("layout-compatibility-report.json", 'blue') . "\n";
|