Example #1
0
        /// <summary>
        /// Performs the request lifecycle, invokes given entry script and cleanups the context.
        /// </summary>
        /// <param name="script">Entry script.</param>
        public void ProcessScript(ScriptInfo script)
        {
            Debug.Assert(script.IsValid);

            // set additional $_SERVER items
            AddServerScriptItems(script);

            // remember the initial script file
            this.MainScriptFile = script;

            //

            try
            {
                if (Debugger.IsAttached)
                {
                    script.Evaluate(this, this.Globals, null);
                }
                else
                {
                    using (_requestTimer = new Timer(RequestTimeout, null, this.Configuration.Core.ExecutionTimeout, Timeout.Infinite))
                    {
                        script.Evaluate(this, this.Globals, null);
                    }
                }
            }
            catch (ScriptDiedException died)
            {
                died.ProcessStatus(this);
            }
        }
Example #2
0
        /// <summary>
        /// Implicit autoload mechanism working through CLR reflection.
        /// This ensures when even the caller does not define PHP class autoloading, we allows seamless use of PHP classes and PHP program.
        /// This mechanism gets enabled by default, disabled only when SPL autoload gets initiated (or anything that sets own <see cref="Context.AutoloadService"/>).
        /// </summary>
        PhpTypeInfo ImplicitAutoloadTypeByName(string fullName)
        {
            if (EnableImplicitAutoload)
            {
                var types = s_assClassMap.LookupTypes(fullName);
                if (types != null)
                {
                    ScriptInfo script = default;

                    for (int i = 0; i < types.Length; i++)
                    {
                        var rpath = types[i].RelativePath;
                        if (script.IsValid)
                        {
                            if (script.Path != rpath)
                            {
                                Trace.WriteLine("Type '" + fullName + "' cannot be autoloaded. Ambiguous declarations in " + script.Path + " and " + rpath);
                                return(null); // ambiguity
                            }
                        }
                        else
                        {
                            script = ScriptsMap.GetDeclaredScript(rpath);
                        }
                    }

                    // pretend we are PHP and include the script:

                    if (script.IsValid && !_scripts.IsIncluded(script.Index))   // include_once:
                    {
                        script.Evaluate(this, this.Globals, null, default);

                        return(GetDeclaredType(fullName, autoload: false)); // TODO: can we return types[0] directly in some cases?
                    }
                }
            }

            return(null);
        }