writeln('Clearing cache...'); $cacheDirs = [ dirname(__DIR__, 3) . '/cache/twig', // Add other cache directories here ]; $hasError = false; foreach ($cacheDirs as $dir) { if (is_dir($dir)) { $output->write("Limpando {$dir}... "); if ($this->deleteDirectory($dir)) { $output->writeln('OK'); // Recreate empty directory if (!is_dir($dir)) { mkdir($dir, 0777, true); chmod($dir, 0777); } } else { $output->writeln('FALHA'); $hasError = true; } } } if ($hasError) { $output->writeln('Alguns caches não puderam ser limpos.'); return Command::FAILURE; } $output->writeln('Cache limpo com sucesso!'); return Command::SUCCESS; } private function deleteDirectory($dir) { if (!file_exists($dir)) { return true; } if (!is_dir($dir)) { return unlink($dir); } foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') { continue; } if (!$this->deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) { return false; } } return rmdir($dir); } }