public static function removeDir($dir)
    {
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
                if ('.' != $object && '..' != $object) {
                    if ('dir' == filetype($dir . DS . $object)) {
                        static::removeDir($dir . DS . $object);
                    } else {
                        if (! unlink($dir . DS . $object)) {
                            throw new ErrorException(
                                'The following file could not be deleted: ' . $dir . DS . $object
                            );
                        }
                    }
                }
            }

            if (! rmdir($dir)) {
                throw new ErrorException("The following directory could not be deleted: {$dir}");
            }
        }
    }