public function expand($types, $keepgroups=false, $keepmimetypes=false) {

        $expanded = [];

        foreach ($this->normalize_file_types($types) as $type) {
            if ($group = $this->is_filetype_group($type)) {
                foreach ($group->extensions as $ext) {
                    $expanded[$ext] = true;
                }
                if ($keepgroups) {
                    $expanded[$type] = true;
                }

            } else if ($this->looks_like_mimetype($type)) {
                // A mime type expands to the associated extensions.
                foreach (file_get_typegroup('extension', [$type]) as $ext) {
                    $expanded[$ext] = true;
                }
                if ($keepmimetypes) {
                    $expanded[$type] = true;
                }

            } else {
                // Single extension expands to itself.
                $expanded[$type] = true;
            }
        }

        return array_keys($expanded);
    }