예제 #1
0
        public PhpArray getDefaultProperties(Context ctx)
        {
            if (_tinfo.isInstantiable)
            {
                var inst = _tinfo.GetUninitializedInstance(ctx);
                if (inst != null)
                {
                    var array = new PhpArray();

                    foreach (var p in TypeMembersUtils.GetDeclaredProperties(_tinfo))
                    {
                        array[p.PropertyName] = p.GetValue(ctx, inst);
                    }

                    return(array);
                }
            }

            //
            throw new NotSupportedException("not instantiable type");
        }
            PhpCallable BindCore(Context ctx, PhpTypeInfo tinfo, object target)
            {
                if (tinfo != null)
                {
                    if (target == null && Target != null && tinfo.Type.IsAssignableFrom(Target.GetType()))
                    {
                        target = this.Target;
                    }

                    var routine = (PhpMethodInfo)tinfo.GetVisibleMethod(_method, _callerCtx);
                    if (routine != null)
                    {
                        if (target != null)
                        {
                            return(routine.PhpInvokable.Bind(target));
                        }
                        else
                        {
                            // calling the method statically
                            if (routine.Methods.All(TypeMembersUtils.IsStatic))
                            {
                                return(routine.PhpCallable);
                            }
                            else
                            {
                                // CONSIDER: compiler (and this binder) creates dummy instance of self;
                                // can we create a special singleton instance marked as "null" so use of $this inside the method will fail ?
                                // TODO: use caller instance or warning (calling instance method statically)
                                return(routine.PhpInvokable.Bind(tinfo.GetUninitializedInstance(ctx)));
                            }
                        }
                    }
                    else
                    {
                        // __call
                        // __callStatic
                        routine = (PhpMethodInfo)tinfo.RuntimeMethods[(target != null)
                            ? TypeMethods.MagicMethods.__call
                            : TypeMethods.MagicMethods.__callstatic];

                        if (routine != null)
                        {
                            return(routine.PhpInvokable.BindMagicCall(target, _method));
                        }
                    }
                }

                return(null);
            }
예제 #3
0
            PhpCallable BindCore(Context ctx, PhpTypeInfo tinfo, object target)
            {
                if (tinfo != null)
                {
                    var method  = _item2.ToString(ctx);
                    var routine = (PhpMethodInfo)tinfo.RuntimeMethods[method];
                    if (routine != null)
                    {
                        if (target != null)
                        {
                            return(routine.PhpInvokable.Bind(target));
                        }
                        else
                        {
                            // calling the method statically
                            if (routine.Methods.All(TypeMembersUtils.IsStatic))
                            {
                                return(routine.PhpCallable);
                            }
                            else
                            {
                                // consider: compiler (and this binder) creates dummy instance of self;
                                // can we create a special singleton instance marked as "null" so use of $this inside the method will fail ?
                                // TODO: use caller instance or warning (calling instance method statically)
                                return(routine.PhpInvokable.Bind(tinfo.GetUninitializedInstance(ctx)));
                            }
                        }
                    }
                    else
                    {
                        // __call
                        // __callStatic
                        routine = (PhpMethodInfo)tinfo.RuntimeMethods[(target != null)
                            ? TypeMethods.MagicMethods.__call
                            : TypeMethods.MagicMethods.__callstatic];

                        if (routine != null)
                        {
                            return(routine.PhpInvokable.BindMagicCall(target, method));
                        }
                    }
                }

                return(null);
            }
예제 #4
0
 public object newInstanceWithoutConstructor(Context ctx) => _tinfo.GetUninitializedInstance(ctx);