public static function decode($header)
    {
        $data = [
            'realm'    => null,
            'username' => null,
            'uri'      => null,
            'nonce'    => null,
            'opaque'   => null,
            'qop'      => null,
            'cnonce'   => null,
            'nc'       => null,
            'response' => null
        ];
        $keys = implode('|', array_keys($data));
        $regex = '~(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))~';
        preg_match_all($regex, $header, $matches, PREG_SET_ORDER);

        foreach ($matches as $m) {
            $data[$m[1]] = $m[3] ? $m[3] : $m[4];
        }
        return $data;
    }