/// <summary> /// /// </summary> /// <param name="Variable"></param> /// <returns></returns> public static string json_encode(Php54Var Variable) { switch (Variable.ReferencedType) { case Php54Var.TypeEnum.Bool: return Variable.BooleanValue ? "true" : "false"; case Php54Var.TypeEnum.Int: return Variable.IntegerValue.ToString(); case Php54Var.TypeEnum.Null: return "null"; case Php54Var.TypeEnum.String: return Php54Utils.StringQuote(Variable.StringValue); case Php54Var.TypeEnum.Array: //Debug.WriteLine((object)Variable.DynamicValue); if (Variable.ArrayValue.PureArray) { var ElementsArray = new List<string>(); foreach (var Pair in Variable.ArrayValue.GetEnumerator()) { ElementsArray.Add(json_encode(Pair.Value)); } return "[" + String.Join(",", ElementsArray) + "]"; } else { var ElementsArray = new List<string>(); foreach (var Pair in Variable.ArrayValue.GetEnumerator()) { ElementsArray.Add( Php54Utils.StringQuote(Pair.Key.ToString()) + ":" + json_encode(Pair.Value) ); } return "{" + String.Join(",", ElementsArray) + "}"; } default: throw(new NotImplementedException()); } }
public static string gettype(Php54Var Value) { switch (Value.ReferencedType) { case Php54Var.TypeEnum.Bool: return "boolean"; case Php54Var.TypeEnum.Int: return "integer"; case Php54Var.TypeEnum.Double: return "double"; case Php54Var.TypeEnum.String: return "string"; case Php54Var.TypeEnum.Null: return "NULL"; } throw(new NotImplementedException()); }
public static void print_r(Php54Var Value, bool ReturnString = false, int IndentLevel = 0) { switch (Value.ReferencedType) { case Php54Var.TypeEnum.Null: Console.WriteLine(""); break; case Php54Var.TypeEnum.Int: Console.WriteLine("{0}", Value.IntegerValue); break; case Php54Var.TypeEnum.String: Console.WriteLine("{0}", Value.StringValue); break; case Php54Var.TypeEnum.Array: Console.WriteLine("Array"); // IndentLevel++; Console.WriteLine(new String(' ', 4 * (IndentLevel + 0)) + "("); int Index = 0; //if (!Value.ArrayValue.PureArray) throw(new NotImplementedException()); foreach (var Pair in Value.ArrayValue.GetEnumerator()) { Console.Write(new String(' ', 4 * (IndentLevel + 1)) + "[{0}] => ", Pair.Key); print_r(Pair.Value, ReturnString, IndentLevel + 2); //Console.WriteLine(""); Index++; } Console.WriteLine(new String(' ', 4 * (IndentLevel + 0)) + ")"); Console.WriteLine(); break; default: throw(new NotImplementedException()); } }
//static public void define(string Name, int Value) public static void define(Php54Scope Scope, string Name, Php54Var Value) { var LeftValue = Scope.Runtime.ConstantScope.GetVariable(Name); Php54Var.Assign(LeftValue, Value); }
public static void var_export(Php54Var Value) { switch (Value.ReferencedType) { case Php54Var.TypeEnum.Null: Console.WriteLine("NULL"); break; case Php54Var.TypeEnum.Int: Console.WriteLine(Value.IntegerValue); break; default: throw (new NotImplementedException()); } }
public static void var_dump(Php54Var Value) { switch (Value.ReferencedType) { case Php54Var.TypeEnum.Null: Console.WriteLine("NULL"); break; case Php54Var.TypeEnum.Int: Console.WriteLine("int({0})", Value.IntegerValue); break; case Php54Var.TypeEnum.Bool: Console.WriteLine("bool({0})", Value.BooleanValue ? "true" : "false"); break; default: throw (new NotImplementedException()); } }
public static void register_shutdown_function(Php54Scope Scope, Php54Var ShutdownFunction) { Scope.Runtime.ShutdownFunction = ShutdownFunction; }