Esempio n. 1
0
            protected override PhpCallable BindCore(Context ctx)
            {
                PhpTypeInfo tinfo;

                if (_item1.IsObject)
                {
                    tinfo = _item1.Object.GetType().GetPhpTypeInfo();
                }
                else
                {
                    tinfo = ctx.GetDeclaredType(_item1.ToString(ctx));
                }

                var method = _item2.ToString(ctx);

                for (; tinfo != null; tinfo = tinfo.BaseType)
                {
                    var routine = (PhpMethodInfo)tinfo.DeclaredMethods[method];
                    if (routine != null)
                    {
                        return(routine.PhpInvokable.Bind(_item1.IsObject ? _item1.Object : null));
                    }
                }

                return(null);
            }
Esempio n. 2
0
            protected override PhpCallable BindCore(Context ctx)
            {
                PhpTypeInfo tinfo;
                object      target = null;

                if (_item1.IsObject)
                {
                    target = _item1.Object;
                    tinfo  = target.GetType().GetPhpTypeInfo();
                }
                else
                {
                    target = null;
                    tinfo  = ctx.GetDeclaredType(_item1.ToString(ctx));
                }

                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: 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);
            }
Esempio n. 3
0
        /// <summary>
		/// Tests whether a given interface is defined.
		/// </summary>
        /// <param name="ctx">Current runtime context.</param>
        /// <param name="ifaceName">The name of the interface.</param>
		/// <param name="autoload">Whether to attempt to call <c>__autoload</c>.</param>
		/// <returns><B>true</B> if the interface given by <paramref name="ifaceName"/> has been defined,
		/// <B>false</B> otherwise.</returns>
		public static bool interface_exists(Context ctx, string ifaceName, bool autoload = true)
        {
            var info = ctx.GetDeclaredType(ifaceName);
            if (info == null && autoload)
            {
                throw new NotImplementedException("autoload");
            }

            //
            return info != null && info.Type.GetTypeInfo().IsInterface;
        }
Esempio n. 4
0
        /// <summary>
		/// Tests whether a given class is defined.
		/// </summary>
        /// <param name="ctx">Current runtime context.</param>
        /// <param name="className">The name of the class.</param>
		/// <param name="autoload">Whether to attempt to call <c>__autoload</c>.</param>
		/// <returns><B>true</B> if the class given by <paramref name="className"/> has been defined,
		/// <B>false</B> otherwise.</returns>
		public static bool class_exists(Context ctx, string className, bool autoload = true)
        {
            var info = ctx.GetDeclaredType(className);
            if (info == null && autoload)
            {
                throw new NotImplementedException("autoload");
            }

            //
            return info != null;
        }
Esempio n. 5
0
            protected override PhpCallable BindCore(Context ctx)
            {
                for (var tinfo = ctx.GetDeclaredType(_class); tinfo != null; tinfo = tinfo.BaseType)
                {
                    var method = (Reflection.PhpMethodInfo)tinfo.DeclaredMethods[_method];
                    if (method != null)
                    {
                        return(method.PhpInvokable.Bind(null));
                    }
                }

                return(null);
            }
Esempio n. 6
0
        /// <summary>
        /// Gets <see cref="PhpTypeInfo"/> from a string or an object instance.
        /// </summary>
        /// <param name="ctx">Current runtime context.</param>
        /// <param name="object">String or object. Other value types cause an exception.</param>
        /// <returns>Corresponding <see cref="PhpTypeInfo"/> descriptor. Cannot be <c>null</c>.</returns>
        public static PhpTypeInfo TypeNameOrObjectToType(Context ctx, PhpValue @object)
        {
            object obj;
            string str;

            if ((obj = (@object.AsObject())) != null)
            {
                return(obj.GetType().GetPhpTypeInfo());
            }
            else if ((str = PhpVariable.AsString(@object)) != null)
            {
                return(ctx.GetDeclaredType(str, true));
            }
            else
            {
                throw new ArgumentException();
            }
        }
Esempio n. 7
0
            protected override PhpCallable BindCore(Context ctx)
            {
                var tinfo   = ctx.GetDeclaredType(_class);
                var routine = (PhpMethodInfo)tinfo?.RuntimeMethods[_method];

                if (routine != null)
                {
                    return(routine.PhpInvokable.Bind(null));
                }
                else if (tinfo != null)
                {
                    routine = (PhpMethodInfo)tinfo.RuntimeMethods[TypeMethods.MagicMethods.__callstatic];
                    if (routine != null)
                    {
                        return(routine.PhpInvokable.BindMagicCall(null, _method));
                    }
                }

                return(null);
            }
Esempio n. 8
0
            protected override PhpCallable BindCore(Context ctx)
            {
                PhpTypeInfo tinfo;
                object      target = null;

                if (_item1.IsObject)
                {
                    target = _item1.Object;
                    tinfo  = target.GetType().GetPhpTypeInfo();
                }
                else
                {
                    target = null;
                    tinfo  = ctx.GetDeclaredType(_item1.ToString(ctx));
                }

                if (tinfo != null)
                {
                    var method  = _item2.ToString(ctx);
                    var routine = (PhpMethodInfo)tinfo.RuntimeMethods[method];
                    if (routine != null)
                    {
                        return(routine.PhpInvokable.Bind(target));
                    }
                    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);
            }
Esempio n. 9
0
            protected override PhpCallable BindCore(Context ctx)
            {
                PhpTypeInfo tinfo;
                
                if (_item1.IsObject)
                {
                    tinfo = _item1.Object.GetType().GetPhpTypeInfo();
                }
                else
                {
                    tinfo = ctx.GetDeclaredType(_item1.ToString(ctx));
                }

                var method = _item2.ToString(ctx);

                for (; tinfo != null; tinfo = tinfo.BaseType)
                {
                    var routine = (PhpMethodInfo)tinfo.DeclaredMethods[method];
                    if (routine != null)
                    {
                        return routine.PhpInvokable.Bind(_item1.IsObject ? _item1.Object : null);
                    }
                }

                return null;
            }
Esempio n. 10
0
            protected override PhpCallable BindCore(Context ctx)
            {
                for (var tinfo = ctx.GetDeclaredType(_class); tinfo != null; tinfo = tinfo.BaseType)
                {
                    var method = (Reflection.PhpMethodInfo)tinfo.DeclaredMethods[_method];
                    if (method != null)
                    {
                        return method.PhpInvokable.Bind(null);
                    }
                }

                return null;
            }