Example #1
0
            public ConsoleContext(params string[] args)
            {
                _rootPath = ScriptsMap.NormalizeSlashes(Directory.GetCurrentDirectory());

                //
                InitOutput(Console.OpenStandardOutput(), Console.Out);

                // Globals
                InitSuperglobals();
                IntializeArgvArgc(args);
            }
Example #2
0
        public RequestContextAspNet(HttpContext httpcontext)
        {
            Debug.Assert(httpcontext != null);
            Debug.Assert(HttpRuntime.UsingIntegratedPipeline);

            _httpctx  = httpcontext;
            _rootPath = ScriptsMap.NormalizeSlashes(HttpRuntime.AppDomainAppPath).TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });

            this.InitOutput(httpcontext.Response.OutputStream);
            this.InitSuperglobals();

            // TODO: start session if AutoStart is On
        }
Example #3
0
        /// <summary>
        /// Resolves path according to PHP semantics, lookups the file in runtime tables and calls its Main method.
        /// </summary>
        /// <param name="cd">Current script directory. Used for relative path resolution. Can be <c>null</c> to not resolve against current directory.</param>
        /// <param name="path">The relative or absolute path to resolve and include.</param>
        /// <param name="locals">Variables scope for the included script.</param>
        /// <param name="this">Reference to <c>this</c> variable.</param>
        /// <param name="once">Whether to include according to include once semantics.</param>
        /// <param name="throwOnError">Whether to include according to require semantics.</param>
        /// <returns>Inclusion result value.</returns>
        public PhpValue Include(string cd, string path, PhpArray locals, object @this = null, bool once = false, bool throwOnError = false)
        {
            ScriptInfo script;

            path = ScriptsMap.NormalizeSlashes(path);

            if (path.StartsWith(this.RootPath, StringComparison.Ordinal)) // rooted
            {
                script = _scripts.GetScript(path.Substring(this.RootPath.Length + 1));
            }
            else
            {
                script = ScriptsMap.SearchForIncludedFile(path, IncludePaths, cd, _scripts.GetScript);
            }

            if (script.IsValid)
            {
                if (once && _scripts.IsIncluded(script.Index))
                {
                    return(PhpValue.Create(true));
                }
                else
                {
                    return(script.MainMethod(this, locals, @this));
                }
            }
            else
            {
                if (TryIncludeFileContent(path))    // include non-compiled file (we do not allow dynamic compilation)
                {
                    return(PhpValue.Null);
                }
                else
                {
                    var cause = string.Format(Resources.ErrResources.script_not_found, path);

                    PhpException.Throw(
                        throwOnError ? PhpError.Error : PhpError.Notice,
                        Resources.ErrResources.script_inclusion_failed, path, cause, string.Join(";", IncludePaths), cd);

                    if (throwOnError)
                    {
                        throw new ArgumentException(cause);
                    }

                    return(PhpValue.False);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Includes requested script file.
        /// </summary>
        public bool Include(HttpRequest req)
        {
            var relative_path = ScriptsMap.NormalizeSlashes(req.PhysicalPath.Substring(req.PhysicalApplicationPath.Length));
            var script        = ScriptsMap.GetDeclaredScript(relative_path);

            if (script.IsValid)
            {
                this.MainScriptFile = script;
                script.Evaluate(this, this.Globals, null);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        public RequestContextCore(HttpContext httpcontext, string rootPath, Encoding encoding)
        {
            Debug.Assert(httpcontext != null);
            Debug.Assert(rootPath != null);
            Debug.Assert(rootPath == ScriptsMap.NormalizeSlashes(rootPath));
            Debug.Assert(rootPath.Length != 0 && rootPath[rootPath.Length - 1] != '/');
            Debug.Assert(encoding != null);

            _httpctx  = httpcontext;
            _rootPath = rootPath;
            _encoding = encoding;

            this.InitOutput(httpcontext.Response.Body, new ResponseTextWriter(httpcontext.Response, encoding));
            this.InitSuperglobals();

            // TODO: start session if AutoStart is On
        }
Example #6
0
        public static ScriptInfo ResolveScript(HttpRequest req)
        {
            var script = default(ScriptInfo);
            var path   = req.Path.Value;
            var isfile = path.Last() != '/';

            // trim slashes
            path = ScriptsMap.NormalizeSlashes(ArrayUtils.Trim(path, '/'));

            if (isfile)
            {
                script = ScriptsMap.GetDeclaredScript(path);
            }

            if (!script.IsValid)
            {
                // path/defaultdocument
                path   = (path.Length != 0) ? (path + ('/' + DefaultDocument)) : DefaultDocument;
                script = ScriptsMap.GetDeclaredScript(path);
            }

            //
            return(script);
        }