public static PhpMethodInfo FindMagicMethod(PhpTypeInfo type, TypeMethods.MagicMethods magic) { return((PhpMethodInfo)type.RuntimeMethods[magic]); }
static Expression BindMagicMethod(PhpTypeInfo type, Type classCtx, Expression target, Expression ctx, TypeMethods.MagicMethods magic, string field, Expression rvalue = null) { var m = FindMagicMethod(type, magic); if (m != null) { var methods = m.Methods.Length == 1 ? (m.Methods[0].IsVisible(classCtx) ? m.Methods : Array.Empty <MethodInfo>()) // optimization for array[1] : m.Methods.Where(x => x.IsVisible(classCtx)).ToArray(); if (methods.Length != 0) { switch (magic) { case TypeMethods.MagicMethods.__set: // __set(name, value) return(OverloadBinder.BindOverloadCall(typeof(void), target, methods, ctx, new Expression[] { Expression.Constant(field), rvalue })); default: // __get(name), __unset(name), __isset(name) return(OverloadBinder.BindOverloadCall(methods[0].ReturnType, target, methods, ctx, new Expression[] { Expression.Constant(field) })); } } else { // TODO: ERR inaccessible } } return(null); }
/// <summary> /// Call the object magic method. /// </summary> /// <typeparam name="T">Object type.</typeparam> /// <param name="target">Object instance.</param> /// <param name="method">Magic method to be called.</param> /// <param name="arguments">Provided arguments.</param> /// <returns>__invoke return value.</returns> public PhpValue Call <T>(T target, TypeMethods.MagicMethods method, params PhpValue[] arguments) where T : class // TODO: check magic exists => ((PhpMethodInfo)TypeInfoHolder <T> .TypeInfo.DeclaredMethods[method]).PhpInvokable(this, target, arguments);