Generic empty class. Used for casting values to an object.
Example #1
0
        /// <summary>
        /// Gets runtime instance fields of <see cref="stdClass"/>.
        /// </summary>
        public static PhpArray GetRuntimeFields(this stdClass obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            return(obj.__peach__runtimeFields);
        }
Example #2
0
            public override object EnsureObject(ref PhpValue me)
            {
                var obj = new stdClass();   // empty class

                // me is changed if me.Boolean == FALSE
                if (me.Boolean == false)
                {
                    me = PhpValue.FromClass(obj);
                }

                return(obj);
            }
Example #3
0
        private static PhpObject FetchFieldInternal(PhpSqlDbResult /*!*/ result, int fieldIndex)
        {
            DataRow info = result.GetSchemaRowInfo(fieldIndex);

            if (info == null)
            {
                return(null);
            }

            string    s;
            PhpObject obj      = new stdClass();
            string    php_type = result.GetPhpFieldType(fieldIndex);

            obj.Add("name", result.GetFieldName(fieldIndex));
            obj.Add("column_source", (s = info["BaseColumnName"] as string) != null ? s : "");
            obj.Add("max_length", result.GetFieldLength(fieldIndex));
            obj.Add("numeric", result.IsNumericType(php_type) ? 1 : 0);
            obj.Add("type", php_type);

            return(obj);
        }
Example #4
0
 /// <summary>
 /// Ensures given variable is not <c>null</c>.
 /// </summary>
 public static object EnsureObject(ref object obj) => obj ?? (obj = new stdClass());
Example #5
0
 /// <summary>
 /// Ensures given variable is not <c>null</c>.
 /// </summary>
 public static object EnsureObject(ref object obj) => obj ?? (obj = new stdClass());
Example #6
0
 public override object EnsureObject(ref PhpValue me)
 {
     var obj = new stdClass();   // empty class
     
     // me is changed if me.Boolean == FALSE
     if (me.Boolean == false)
         me = PhpValue.FromClass(obj);
     
     return obj;
 }
Example #7
0
		private static PhpObject FetchFieldInternal(PhpSqlDbResult/*!*/ result, int fieldIndex)
		{
			DataRow info = result.GetSchemaRowInfo(fieldIndex);
			if (info == null) return null;

			string s;
			PhpObject obj = new stdClass();
			string php_type = result.GetPhpFieldType(fieldIndex);

			obj.Add("name", result.GetFieldName(fieldIndex));
			obj.Add("column_source", (s = info["BaseColumnName"] as string) != null ? s : "");
			obj.Add("max_length", result.GetFieldLength(fieldIndex));
			obj.Add("numeric", result.IsNumericType(php_type) ? 1 : 0);
			obj.Add("type", php_type);

			return obj;
		}
Example #8
0
            /// <summary>
            /// Converts instances of user-defined PHP classes to <see cref="stdClass"/>es. Also converts all
            /// strings to the <see cref="System.String"/> representation.
            /// </summary>
            /// <param name="node"></param>
            /// <param name="context">Current <see cref="ScriptContext"/>.</param>
            /// <returns></returns>
            internal static object PreCallObjectTransform(IPhpObjectGraphNode node, ScriptContext context)
            {
                DObject obj = node as DObject;
                if (obj != null && !obj.GetType().FullName.StartsWith(Namespaces.Library))
                {
                    // simulate "marshal-by-ref" semantics for user-defined classes
                    stdClass std = new stdClass(context);

                    string id = Guid.NewGuid().ToString();
                    std.SetProperty(ObjectIdentityFieldName, id, null);

                    (objectIdentities ?? (objectIdentities = new Dictionary<string, DObject>()))[id] = obj;

                    return std;
                }

                if (node is PhpString)
                    return ((IPhpConvertible)node).ToString();
                
                return node;
            }
Example #9
0
        protected override void DoAction(int action)
        {
            switch (action)
            {
            case 2: // start -> value
            { Result = value_stack.array[value_stack.top - 1].yyval.obj; }
                return;

            case 3: // object -> OBJECT_OPEN members OBJECT_CLOSE
            {
                var elements = (List <KeyValuePair <string, object> >)value_stack.array[value_stack.top - 2].yyval.obj;

                if (decodeOptions.Assoc)
                {
                    var arr = new PhpArray(elements.Count);

                    foreach (var item in elements)
                    {
                        arr.Add(PHP.Core.Convert.StringToArrayKey(item.Key), item.Value);
                    }

                    yyval.obj = arr;
                }
                else
                {
                    var std = new stdClass(context, true);
                    std.AddRange(elements);
                    yyval.obj = std;
                }
            }
                return;

            case 4: // object -> OBJECT_OPEN OBJECT_CLOSE
            { yyval.obj = new stdClass(context, true); }
                return;

            case 5: // members -> pair ITEMS_SEPARATOR members
            {
                var elements = (List <KeyValuePair <string, object> >)value_stack.array[value_stack.top - 1].yyval.obj;
                var result   = new List <KeyValuePair <string, object> >(elements.Count + 1)
                {
                    (KeyValuePair <string, object>)value_stack.array[value_stack.top - 3].yyval.obj
                };
                result.AddRange(elements);
                yyval.obj = result;
            }
                return;

            case 6: // members -> pair
            { yyval.obj = new List <KeyValuePair <string, object> >()
              {
                  (KeyValuePair <string, object>)value_stack.array[value_stack.top - 1].yyval.obj
              }; }
                return;

            case 7: // pair -> STRING NAMEVALUE_SEPARATOR value
            { yyval.obj = new KeyValuePair <string, object>((string)value_stack.array[value_stack.top - 3].yyval.obj, value_stack.array[value_stack.top - 1].yyval.obj); }
                return;

            case 8: // array -> ARRAY_OPEN elements ARRAY_CLOSE
            {
                var elements = (List <object>)value_stack.array[value_stack.top - 2].yyval.obj;
                var arr      = new PhpArray(elements.Count);

                foreach (var item in elements)
                {
                    arr.Add(item);
                }

                yyval.obj = arr;
            }
                return;

            case 9: // array -> ARRAY_OPEN ARRAY_CLOSE
            { yyval.obj = new PhpArray(); }
                return;

            case 10: // elements -> value ITEMS_SEPARATOR elements
            {
                var elements = (List <object>)value_stack.array[value_stack.top - 1].yyval.obj;
                var result   = new List <object>(elements.Count + 1)
                {
                    value_stack.array[value_stack.top - 3].yyval.obj
                };
                result.AddRange(elements);
                yyval.obj = result;
            }
                return;

            case 11: // elements -> value
            { yyval.obj = new List <object>()
              {
                  value_stack.array[value_stack.top - 1].yyval.obj
              }; }
                return;

            case 12: // value -> STRING
            { yyval.obj = value_stack.array[value_stack.top - 1].yyval.obj; }
                return;

            case 13: // value -> INTEGER
            { yyval.obj = value_stack.array[value_stack.top - 1].yyval.obj; }
                return;

            case 14: // value -> DOUBLE
            { yyval.obj = value_stack.array[value_stack.top - 1].yyval.obj; }
                return;

            case 15: // value -> object
            { yyval.obj = value_stack.array[value_stack.top - 1].yyval.obj; }
                return;

            case 16: // value -> array
            { yyval.obj = value_stack.array[value_stack.top - 1].yyval.obj; }
                return;

            case 17: // value -> TRUE
            { yyval.obj = true; }
                return;

            case 18: // value -> FALSE
            { yyval.obj = false; }
                return;

            case 19: // value -> NULL
            { yyval.obj = null; }
                return;
            }
        }