#!/usr/bin/env php
<?php
function clean($dir)
{
    $files = scandir($dir);
    foreach ($files as $file) {
        $full_path = "{$dir}/{$file}";
        if ($file[0]=== '.') {
            continue;
        }
        if (is_dir($full_path)) {
            clean($full_path);
            continue;
        }
        $extension = pathinfo($file, PATHINFO_EXTENSION);
        if (in_array($extension, ['diff', 'exp', 'log', 'out', 'php', 'sh'], true)) {
            if (is_file($full_path)) {
                // echo "DELETE: {$full_path}\n";
                unlink($full_path);
            }
        }
    }
}

$dirs = scandir(__DIR__);
foreach ($dirs as $dir) {
    if (strpos($dir, 'swoole_') === 0) {
        clean(__DIR__ . '/' . $dir);
    }
}
