Exemple #1
0
        /// <summary>
        /// Sets user defined handler to handle errors.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="newHandler">The user callback called to handle an error.</param>
        /// <param name="errorTypes">Error types to be handled by the handler.</param>
        /// <returns>
        /// The PHP representation of previous user handler, <B>null</B> if there is no user one, or
        /// <B>false</B> if <paramref name="newHandler"/> is invalid or empty.
        /// </returns>
        /// <remarks>
        /// Stores old user handlers on the stack so that it is possible to
        /// go back to arbitrary previous user handler.
        /// </remarks>
        public static PhpValue set_error_handler(Context ctx, IPhpCallable newHandler, PhpErrorSets errorTypes = PhpErrorSets.Handleable)
        {
            if (newHandler == null)
            {
                return(PhpValue.Null);
            }
            if (newHandler is PhpCallback && !((PhpCallback)newHandler).IsValid)
            {
                return(PhpValue.Null);
            }

            var errctx = GetErrorContext(ctx);

            //var old_handler = ctx.UserErrorHandler;
            //var old_handlers = errctx.OldUserErrorHandlers;

            //// previous handler was defined by user => store it into the stack:
            //if (old_handler != null)
            //{
            //    if (old_handlers == null)
            //    {
            //        old_handlers = new Stack(5);
            //        RequestContext.RequestEnd += new Action(ClearOldUserHandlers);
            //    }
            //    old_handlers.Push(new ErrorHandlerRecord(old_handler, old_errors));
            //}

            //// sets the current handler:
            //Configuration.Local.ErrorControl.UserHandler = newHandler;
            //Configuration.Local.ErrorControl.UserHandlerErrors = (PhpError)errorTypes;

            //// returns the previous handler:
            //return (old_handler != null) ? old_handler.ToPhpRepresentation() : null;
            return(PhpValue.Null);
        }
Exemple #2
0
        /// <summary>
        /// Sets user defined handler to handle errors.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="newHandler">The user callback called to handle an error.</param>
        /// <param name="errorTypes">Error types to be handled by the handler.</param>
        /// <returns>
        /// The PHP representation of previous user handler, <B>null</B> if there is no user one, or
        /// <B>false</B> if <paramref name="newHandler"/> is invalid or empty.
        /// </returns>
        /// <remarks>
        /// Stores old user handlers on the stack so that it is possible to
        /// go back to arbitrary previous user handler.
        /// </remarks>
        public static PhpValue set_error_handler(Context ctx, IPhpCallable newHandler, PhpErrorSets errorTypes = PhpErrorSets.Handleable)
        {
            if (newHandler == null)
            {
                return(PhpValue.Null);
            }
            if (newHandler is PhpCallback && !((PhpCallback)newHandler).IsValid)
            {
                return(PhpValue.Null);
            }

            var config = ctx.Configuration.Core;

            var oldhandler = config.UserErrorHandler;
            var oldtypes   = config.UserErrorTypes;

            if (oldhandler != null)
            {
                GetErrorContext(ctx).StoreErrorHandler(new ErrorHandlerRecord(oldhandler, oldtypes));
            }

            config.UserErrorHandler = newHandler;
            config.UserErrorTypes   = (PhpError)errorTypes;

            // returns the previous handler:
            return((oldhandler != null)
                ? oldhandler.ToPhpValue()
                : PhpValue.Null);
        }