Пример #1
0
        public static bool Register(NamingContext namingContext, DTypeDesc caller, PhpCallback autoloadFunction, bool throwError, bool prepend)
        {
            if (autoloadFunction == null)
            {
                PhpException.ArgumentNull("autoloadFunction");
                return(false);
            }

            if (autoloadFunction.Bind(!throwError, caller, namingContext))
            {
                var context = ScriptContext.CurrentContext;
                if (FindAutoloadFunction(context, autoloadFunction.ToPhpRepresentation()) != null)
                {
                    return(false);
                }

                if (prepend)
                {
                    context.SplAutoloadFunctions.AddFirst(autoloadFunction);
                }
                else
                {
                    context.SplAutoloadFunctions.AddLast(autoloadFunction);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public static bool Start(PhpCallback filter, int chunkSize, bool erase)
        {
            if (chunkSize != 0)
            {
                PhpException.ArgumentValueNotSupported("chunkSize", "!= 0");
            }
            if (!erase)
            {
                PhpException.ArgumentValueNotSupported("erase", erase);
            }

            ScriptContext context = ScriptContext.CurrentContext;

            context.BufferedOutput.IncreaseLevel();

            bool result = true;

            // skips filter setting if filter is not specified or valid:
            if (filter != null && (result = filter.Bind()))
            {
                context.BufferedOutput.SetFilter(filter);
            }

            context.IsOutputBuffered = true;
            return(result);
        }
Пример #3
0
        public static bool IsCallable(PHP.Core.Reflection.DTypeDesc caller, object variable, bool syntaxOnly, out string callableName)
        {
            PhpCallback callback = PHP.Core.Convert.ObjectToCallback(variable, true);

            if (callback == null || callback.IsInvalid)
            {
                callableName = PHP.Core.Convert.ObjectToString(variable);
                return(false);
            }

            callableName = ((IPhpConvertible)callback).ToString();
            return(syntaxOnly ? true : callback.Bind(true, caller, null));
        }
Пример #4
0
        private object InvokeFunctionCore(string name, params object[] args)
        {
            // check whether this function is allowed to be called
            PhpCallback callback;

            if (allFunctionsRegistered)
            {
                registeredFunctions.TryGetValue(name, out callback);
            }
            else
            {
                if (registeredFunctions.TryGetValue(name, out callback))
                {
                    PhpException.Throw(PhpError.Warning, String.Format(Resources.HandlerNotAllowed, name));
                    return(null);
                }
            }

            // if the callback does not already exists, create it
            if (callback == null)
            {
                // parse name
                int index = name.IndexOf("::");
                switch (index)
                {
                case -1: callback = new PhpCallback(name); break;

                case 0: callback = new PhpCallback(name.Substring(2)); break;

                default: callback = new PhpCallback(name.Substring(0, index), name.Substring(index + 2)); break;
                }

                if (!callback.Bind())
                {
                    return(null);
                }

                registeredFunctions[name] = callback;
            }

            // convert arguments
            for (int i = 0; i < args.Length; i++)
            {
                args[i] = XsltConvertor.DotNetToPhp(args[i]);
            }

            // invoke!
            return(callback.Invoke(args));
        }
Пример #5
0
            public void BindOrBiteMyLegsOff(DTypeDesc caller, NamingContext namingContext)
            {
                if (Callback != null)
                {
                    if (Callback.TargetInstance == null && Parser._handlerObject != null)
                    {
                        _currentCallback = new PhpCallback(Parser._handlerObject, Callback.RoutineName);
                    }
                    else
                    {
                        _currentCallback = Callback;
                    }

                    Bound = _currentCallback.Bind(true, caller, namingContext);
                }
                else
                {
                    Bound = false;
                }
            }
Пример #6
0
        public static DObject CreateClrThread(PhpCallback /*!*/ callback, params object[] args)
        {
            if (callback == null)
            {
                PhpException.ArgumentNull("callback");
            }

            if (!callback.Bind())
            {
                return(null);
            }

            object[] copies = (args != null) ? new object[args.Length] : ArrayUtils.EmptyObjects;

            for (int i = 0; i < copies.Length; i++)
            {
                copies[i] = PhpVariable.DeepCopy(args[i]);
            }

            return(ClrObject.WrapRealObject(ThreadPool.QueueUserWorkItem(new Worker(ScriptContext.CurrentContext, copies).Run, callback)));
        }