コード例 #1
0
ファイル: Operators.cs プロジェクト: allisterb/peachpie
 public static IPhpArray EnsureItemArray(IPhpArray array, PhpValue index)
 {
     if (Convert.TryToIntStringKey(index, out IntStringKey key))
     {
         return(array.EnsureItemArray(key));
     }
     else
     {
         throw new ArgumentException();
     }
 }
コード例 #2
0
 static IPhpArray EnsureItemArray(IPhpArray array, string key)
 {
     if (string.IsNullOrEmpty(key))
     {
         var newarr = new PhpArray();
         array.AddValue(PhpValue.Create(newarr));
         return(newarr);
     }
     else
     {
         return(array.EnsureItemArray(new IntStringKey(key)));
     }
 }
コード例 #3
0
 static IPhpArray EnsureItemArray(IPhpArray array, IntStringKey key)
 {
     if (key.Equals(IntStringKey.EmptyStringKey))
     {
         var newarr = new PhpArray();
         array.AddValue(PhpValue.Create(newarr));
         return(newarr);
     }
     else
     {
         return(array.EnsureItemArray(key));
     }
 }
コード例 #4
0
ファイル: Operators.cs プロジェクト: allisterb/peachpie
        public static PhpAlias EnsureItemAlias(IPhpArray array, PhpValue index, bool quiet)
        {
            if (Convert.TryToIntStringKey(index, out IntStringKey key))
            {
                return(array.EnsureItemAlias(key));
            }
            else
            {
                if (!quiet)
                {
                    throw new ArgumentException();
                }

                return(new PhpAlias(PhpValue.Void));
            }
        }
コード例 #5
0
ファイル: Conversions.cs プロジェクト: windsOne/peachpie
        /// <summary>
        /// Converts given array object to <see cref="stdClass"/>.
        /// </summary>
        /// <param name="array">Non-null reference to a PHP array.</param>
        /// <returns>New instance of <see cref="stdClass"/> with runtime fields filled from given array.</returns>
        public static object ToClass(IPhpArray array)
        {
            var convertible = array as IPhpConvertible;

            if (convertible != null)
            {
                return(convertible.ToClass());
            }
            else
            {
                //return new stdClass()
                //{
                //    __peach__runtimeFields = new PhpArray(array);
                //};
                throw new NotImplementedException();
            }
        }
コード例 #6
0
 /// <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);
 }
コード例 #7
0
ファイル: Conversions.cs プロジェクト: windsOne/peachpie
 public static int ToDouble(this IPhpArray value) => ToInt(value);
コード例 #8
0
ファイル: Conversions.cs プロジェクト: windsOne/peachpie
 public static int ToLong(this IPhpArray value) => ToInt(value);
コード例 #9
0
ファイル: Conversions.cs プロジェクト: windsOne/peachpie
 public static int ToInt(this IPhpArray value) => value.Count;
コード例 #10
0
        /// <summary>
        /// Adds a variable to auto-global array.
        /// Duplicit entries are collected into a sub-array item.
        /// The routine respects <c>[subkey]</c> notation to build a hierarchy of sub-arrays.
        /// </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(this IPhpArray /*!*/ array, string name, string value, string subname = null)
        {
            Debug.Assert(array != null);
            Debug.Assert(name != null);
            Debug.Assert(value != null);

            string key;

            // current left and right square brace positions:
            int left, right;

            // checks pattern {var_name}[{key1}][{key2}]...[{keyn}] where var_name is [^[]* and keys are [^]]*:
            left = name.IndexOf('[');
            if (left > 0 && left < name.Length - 1 && (right = name.IndexOf(']', left + 1)) >= 0)
            {
                // the variable name is a key to the "array", dots are replaced by underscores in top-level name:
                key = EncodeTopLevelName(name.Substring(0, left));

                // ensures that all [] operators in the chain except for the last one are applied on an array:
                for (;;)
                {
                    // adds a level keyed by "key":
                    array = EnsureItemArray(array, key);

                    // adds a level keyed by "subname" (once only):
                    if (subname != null)
                    {
                        array   = EnsureItemArray(array, subname);
                        subname = null;
                    }

                    // next key:
                    key = name.Substring(left + 1, right - left - 1);

                    // breaks if ']' is not followed by '[':
                    left = right + 1;
                    if (left == name.Length || name[left] != '[')
                    {
                        break;
                    }

                    // the next right brace:
                    right = name.IndexOf(']', left + 1);
                }

                if (string.IsNullOrEmpty(key))
                {
                    array.AddValue(PhpValue.Create(value));
                }
                else
                {
                    array.SetItemValue(new IntStringKey(key), PhpValue.Create(value));
                }
            }
            else
            {
                // no array pattern in variable name, "name" is a top-level key:
                name = EncodeTopLevelName(name);

                // inserts a subname on the next level:
                if (subname != null)
                {
                    EnsureItemArray(array, name).SetItemValue(new IntStringKey(subname), PhpValue.Create(value));
                }
                else
                {
                    array.SetItemValue(new IntStringKey(name), PhpValue.Create(value));
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Ensures given variable is not <c>null</c>.
 /// </summary>
 public static IPhpArray EnsureArray(ref IPhpArray arr) => arr ?? (arr = new PhpArray());
コード例 #12
0
ファイル: Operators.cs プロジェクト: iolevel/peachpie
 /// <summary>
 /// Ensures given variable is not <c>null</c>.
 /// </summary>
 public static IPhpArray EnsureArray(ref IPhpArray arr) => arr ?? (arr = new PhpArray());
コード例 #13
0
ファイル: Conversions.cs プロジェクト: iolevel/peachpie
 /// <summary>
 /// Converts given array object to <see cref="stdClass"/>.
 /// </summary>
 /// <param name="array">Non-null reference to a PHP array.</param>
 /// <returns>New instance of <see cref="stdClass"/> with runtime fields filled from given array.</returns>
 public static object ToClass(IPhpArray array)
 {
     var convertible = array as IPhpConvertible;
     if (convertible != null)
     {
         return convertible.ToClass();
     }
     else
     {
         //return new stdClass()
         //{
         //    __peach__runtimeFields = new PhpArray(array);
         //};
         throw new NotImplementedException();
     }
 }