Exemplo n.º 1
0
        public static bool ResetRewriteVariables()
        {
            /*PhpException.FunctionNotSupported();
             * return false;*/


            ScriptContext  context  = ScriptContext.CurrentContext;
            UrlRewriter    rewriter = UrlRewriter.Current;
            BufferedOutput output   = context.BufferedOutput;

            if (rewriter == null ||
                output.Level == 0 ||
                output.GetFilter() != rewriter.filterCallback)
            {
                return(false);
            }

            // some output flush
            output.Flush();

            rewriter.Variables.Clear();
            output.DecreaseLevel(false);

            if (output.Level == 0)
            {
                context.IsOutputBuffered = false;
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the status of the current or all output buffers.
        /// </summary>
        /// <param name="ctx">Current runtime context.</param>
        /// <param name="full">Whether to retrieve extended information about all levels of buffering or about the current one.</param>
        /// <returns>The array of name => value pairs containing information.</returns>
        public static PhpArray ob_get_status(Context ctx, bool full)
        {
            BufferedOutput bo = ctx.BufferedOutput;
            PhpArray       result;

            if (full)
            {
                result = new PhpArray(bo.Level);
                for (int i = 1; i <= bo.Level; i++)
                {
                    result.Add(i, GetLevelStatus(bo, i));
                }
            }
            else if (bo.Level > 0)
            {
                result = GetLevelStatus(bo, bo.Level);
                result.Add("level", bo.Level);
            }
            else
            {
                result = PhpArray.NewEmpty();
            }

            return(result);
        }
Exemplo n.º 3
0
        public static bool AddRewriteVariable(string name, string value)
        {
            if (String.IsNullOrEmpty(name))
            {
                PhpException.InvalidArgument("name", LibResources.GetString("arg:null_or_empty"));
                return(false);
            }

            ScriptContext  context  = ScriptContext.CurrentContext;
            UrlRewriter    rewriter = UrlRewriter.GetOrCreate();
            BufferedOutput output   = context.BufferedOutput;

            // some output flush
            output.Flush();

            rewriter.Variables[name] = value;

            // start UrlRewriter filtering if not yet
            if (output.FindLevelByFilter(rewriter.filterCallback) < 0)
            {
                // create new output buffer level (URL-Rewriter is not started yet)
                int Level = output.IncreaseLevel();
                output.SetFilter(rewriter.GetOrCreateFilterCallback(context), Level);
                output.SetLevelName(Level, "URL-Rewriter");
            }

            context.IsOutputBuffered = true;    // turn on output buffering if not yet

            return(true);
        }
Exemplo n.º 4
0
        public void LogText(LogLevel logLevel, String strInText, params object[] parms)
        {
            String output = String.Format(strInText, parms);

            BufferedOutput cached;

            try
            {
                _outputListLock.Lock();
                if (_outputByText.TryGetValue(output, out cached) == false)
                {
                    cached = new BufferedOutput(logLevel, DateTime.UtcNow, output);
                    _outputByText.Add(output, cached);
                }
                cached.AddInstance();

                int count;
                if (cached.TryGetOutput(_minumumOutputInterval, out count))
                {
                    _log.LogText(logLevel, String.Format("{0} - ({1} times)", output, count));
                    _outputByText.Remove(output);
                }
            }
            finally
            {
                _outputListLock.Unlock();
            }

            CheckCache();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the content of the current buffer and decreases the level of buffering.
        /// </summary>
        /// <returns>The content of the buffer.</returns>
        public static PhpValue ob_get_flush(Context ctx)
        {
            BufferedOutput bo = ctx.BufferedOutput;

            var result = bo.GetContent();

            EndInternal(ctx, true);
            return(result);
        }
Exemplo n.º 6
0
        public static object GetAndFlush()
        {
            ScriptContext  context = ScriptContext.CurrentContext;
            BufferedOutput bo      = context.BufferedOutput;

            object result = bo.GetContent();

            EndInternal(context, true);
            return(result);
        }
Exemplo n.º 7
0
        public static PhpArray ob_list_handlers(Context ctx)
        {
            BufferedOutput bo     = ctx.BufferedOutput;
            var            result = new PhpArray(bo.Level);

            for (int i = 0; i < bo.Level; i++)
            {
                result.Add(bo.GetLevelName(i));
            }

            return(result);
        }
Exemplo n.º 8
0
        public static PhpArray GetHandlers()
        {
            BufferedOutput bo     = ScriptContext.CurrentContext.BufferedOutput;
            PhpArray       result = new PhpArray(bo.Level, 0);

            for (int i = 0; i < bo.Level; i++)
            {
                result.Add(bo.GetLevelName(i));
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Decreases the level of buffering and discards or flushes data on the current level of buffering.
        /// </summary>
        /// <param name="context">Current script context.</param>
        /// <param name="flush">Whether to flush data.</param>
        /// <returns>Whether the content was discarded and the level was decreased.</returns>
        private static bool EndInternal(ScriptContext /*!*/ context, bool flush)
        {
            BufferedOutput buf = context.BufferedOutput;

            if (buf.Level == 0)
            {
                PhpException.Throw(PhpError.Notice, CoreResources.GetString("output_buffering_disabled"));
                return(false);
            }

            if (buf.DecreaseLevel(flush) < 0)
            {
                context.IsOutputBuffered = false;
            }

            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Decreases the level of buffering and discards or flushes data on the current level of buffering.
        /// </summary>
        /// <param name="ctx">Current runtime context.</param>
        /// <param name="flush">Whether to flush data.</param>
        /// <returns>Whether the content was discarded and the level was decreased.</returns>
        private static bool EndInternal(Context /*!*/ ctx, bool flush)
        {
            BufferedOutput buf = ctx.BufferedOutput;

            if (buf.Level == 0)
            {
                //PhpException.Throw(PhpError.Notice, CoreResources.GetString("output_buffering_disabled"));
                //return false;
                throw new NotImplementedException();
            }

            if (buf.DecreaseLevel(flush) < 0)
            {
                ctx.IsOutputBuffered = false;
            }

            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Decreases the level of buffering and discards or flushes data on the current level of buffering.
        /// </summary>
        /// <param name="ctx">Current runtime context.</param>
        /// <param name="flush">Whether to flush data.</param>
        /// <returns>Whether the content was discarded and the level was decreased.</returns>
        private static bool EndInternal(Context /*!*/ ctx, bool flush)
        {
            BufferedOutput buf = ctx.BufferedOutput;

            if (buf.Level == 0)
            {
                // "failed to delete buffer. No buffer to delete"
                PhpException.Throw(PhpError.Notice, Core.Resources.ErrResources.output_buffering_disabled);
                return(false);
            }

            if (buf.DecreaseLevel(flush) < 0)
            {
                ctx.IsOutputBuffered = false;
            }

            return(true);
        }
Exemplo n.º 12
0
        private static PhpArray /*!*/ GetLevelStatus(BufferedOutput /*!*/ bo, int index)
        {
            PhpArray result = new PhpArray(0, 3);

            PhpCallback filter;
            int         size;

            bo.GetLevelInfo(index, out filter, out size);

            if (filter != null)
            {
                result.Add("type", 1);
                result.Add("name", ((IPhpConvertible)filter).ToString());
            }
            else
            {
                result.Add("type", 0);
            }
            result.Add("buffer_size", size);

            return(result);
        }
Exemplo n.º 13
0
        private static PhpArray /*!*/ GetLevelStatus(BufferedOutput /*!*/ bo, int index)
        {
            var result = new PhpArray(3);

            IPhpCallable filter;
            int          size;
            string       name;

            bo.GetLevelInfo(index, out filter, out size, out name);

            if (filter != null)
            {
                result.Add("type", 1);
                result.Add("name", name);
            }
            else
            {
                result.Add("type", 0);
            }
            result.Add("buffer_size", size);

            return(result);
        }
Exemplo n.º 14
0
        public static PhpArray GetStatus(bool full)
        {
            BufferedOutput bo = ScriptContext.CurrentContext.BufferedOutput;
            PhpArray       result;

            if (full)
            {
                result = new PhpArray(bo.Level, 0);
                for (int i = 1; i <= bo.Level; i++)
                {
                    result.Add(i, GetLevelStatus(bo, i));
                }
            }
            else if (bo.Level > 0)
            {
                result = GetLevelStatus(bo, bo.Level);
                result.Add("level", bo.Level);
            }
            else
            {
                result = new PhpArray(0, 0);
            }
            return(result);
        }