Beispiel #1
0
 /// <summary>
 /// Called when an option (i.e. a key-value pair) is encountered.
 /// </summary>
 public void ProcessOption(IntStringKey key, string value)
 {
     if (key.IsString)
     {
         NameValueCollectionUtils.AddVariable(_currentSection, key.String, value, rawname: true);
     }
     else
     {
         _currentSection[key] = value;
     }
 }
Beispiel #2
0
            /// <summary>
            /// Adds a form file to the <c>$_FILES</c> array.
            /// </summary>
            /// <param name="files">The $_FILES array.</param>
            /// <param name="field_name">Form field name.</param>
            /// <param name="file_name">Original file name, without the directory name.</param>
            /// <param name="type">Content type.</param>
            /// <param name="tmp_name">Local full file path where is the uploaded file temporarily stored.</param>
            /// <param name="error">Error code number.</param>
            /// <param name="file_length">Uploaded file size in bytes.</param>
            public static void AddFormFile(PhpArray /*!*/ files, string field_name, string file_name, string type, string tmp_name, int error, long file_length)
            {
                // field_name
                // field_name[]
                // field_name[key]

                var left = field_name.IndexOf('[');

                if (left > 0 && left < field_name.Length - 1)
                {
                    var right = field_name.IndexOf(']', left + 1);
                    if (right > 0)
                    {
                        // keyed file entry:

                        // the variable name is a key to the "array", dots are replaced by underscores in top-level name:
                        var field_name_key = new IntStringKey(NameValueCollectionUtils.EncodeTopLevelName(field_name.Substring(0, left)));
                        var file_entry     = NameValueCollectionUtils.EnsureItemArray(files, field_name_key);

                        // file entry key,
                        // can be a string, empty or a number
                        var key = Convert.StringToArrayKey(field_name.Substring(left + 1, right - left - 1));

                        NameValueCollectionUtils.EnsureItemArray(file_entry, "name", key, file_name);
                        NameValueCollectionUtils.EnsureItemArray(file_entry, "type", key, type);
                        NameValueCollectionUtils.EnsureItemArray(file_entry, "tmp_name", key, tmp_name);
                        NameValueCollectionUtils.EnsureItemArray(file_entry, "error", key, error);
                        NameValueCollectionUtils.EnsureItemArray(file_entry, "size", key, file_length);

                        //
                        return;
                    }
                }

                // not keyed:
                AddVariable(files, field_name, new PhpArray(5)
                {
                    { "name", file_name },
                    { "type", type },
                    { "tmp_name", tmp_name },
                    { "error", error },
                    { "size", file_length },
                });
            }
Beispiel #3
0
 /// <summary>
 /// Adds a variable into the array while keeping duplicit keys in sub-arrays of indexed items.
 /// </summary>
 /// <param name="name">Key, respecting <c>[subkey]</c> notation.</param>
 /// <param name="value">The value.</param>
 /// <remarks>See <see cref="NameValueCollectionUtils.AddVariable(IPhpArray, string, string, string)"/> for details.</remarks>
 public void AddVariable(string name, string value) => NameValueCollectionUtils.AddVariable(this, name, value);
 /// <summary>
 /// Adds a variable to auto-global array.
 /// </summary>
 /// <param name="array">The array.</param>
 /// <param name="name">A unparsed name of variable.</param>
 /// <param name="value">A value to be added.</param>
 /// <param name="subname">A name of intermediate array inserted before the value.</param>
 public static void AddVariable(IPhpArray /*!*/ array, string name, string value, string subname = null)
 {
     NameValueCollectionUtils.AddVariable(array, name, value, subname);
 }