protected function flushDirectory($path, $delete = false)
    {
        if (is_dir($path)) {
            $entries = scandir($path);
            foreach ($entries as $entry) {
                $exclude = array_merge(array('.', '..'), $this->exclude);
                if (in_array($entry, $exclude)) {
                    continue;
                }
                $entryPath = $path . '/' . $entry;
                if (!is_link($entryPath) && is_dir($entryPath)) {
                    $this->flushDirectory($entryPath, true);
                } else {
                    unlink($entryPath);
                }
            }
            if ($delete) {
                rmdir($path);
            }
        }
    }