protected function deleteTree($directory, $removeBaseDir = false)
    {
        $files = array_diff(scandir($directory), array('.', '..'));
        foreach ($files as $file) {
            (is_dir("$directory/$file")) ? $this->deleteTree("$directory/$file", true) : @unlink("$directory/$file");
        }

        if ($removeBaseDir) {
            @rmdir($directory);
        }
    }