PHP.Core.ScriptContext.InitApplication C# (CSharp) Метод

InitApplication() публичный статический Метод

Initializes the script context for a PHP console application.
Use this method if you want to initialize application in the same way the PHP console/Windows application is initialized. The returned script context is initialized as follows: The application's source root is set. The main script of the application is defined. Output and input streams are set to standard output and input, respectively. Current culture it set to CultureInfo.InvariantCulture. Auto-global variables ($_GET, $_SET, etc.) are initialized. Working directory is set tothe current working directory.
/// Web configuration is invalid. The context is not initialized then. ///
public static InitApplication ( PHP.Core.ApplicationContext appContext, Type mainScript, string relativeSourcePath, string sourceRoot ) : ScriptContext
appContext PHP.Core.ApplicationContext Application context.
mainScript System.Type The main script's type or a null reference for a pure application.
relativeSourcePath string A path to the main script source file.
sourceRoot string A source root within which an application has been compiler.
Результат ScriptContext
        public static ScriptContext/*!*/ InitApplication(ApplicationContext/*!*/ appContext, Type mainScript,
            string relativeSourcePath, string sourceRoot)
        {
            // loads configuration into the given application context 
            // (applies only if the config has not been loaded yet by the current thread):
            Configuration.Load(appContext);

            ApplicationConfiguration app_config = Configuration.Application;

            if (mainScript != null)
            {
                if (relativeSourcePath == null)
                    throw new ArgumentNullException("relativeSourcePath");

                if (sourceRoot == null)
                    throw new ArgumentNullException("sourceRoot");

                // overrides source root configuration if not explicitly specified in config file:
                if (!app_config.Compiler.SourceRootSet)
                    app_config.Compiler.SourceRoot = new FullPath(sourceRoot);
            }

            // takes a writable copy of a global configuration:
            LocalConfiguration config = (LocalConfiguration)Configuration.DefaultLocal.DeepCopy();

            // sets invariant culture as a default one:
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            ScriptContext result = new ScriptContext(appContext, config, Console.Out, Console.OpenStandardOutput());

            result.IsOutputBuffered = result.config.OutputControl.OutputBuffering;
            result.AutoGlobals.Initialize(config, null);
            result.WorkingDirectory = Directory.GetCurrentDirectory();
            result.ThrowExceptionOnError = true;
            result.config.ErrorControl.HtmlMessages = false;

            if (mainScript != null)
            {
                // converts relative path of the script source to full canonical path using source root from the configuration:
                PhpSourceFile main_source_file = new PhpSourceFile(
                    app_config.Compiler.SourceRoot,
                    new FullPath(relativeSourcePath, app_config.Compiler.SourceRoot)
                );

                result.DefineMainScript(new ScriptInfo(mainScript), main_source_file);
            }

            ScriptContext.CurrentContext = result;

            Externals.BeginRequest();
            result.FinallyDispose += Externals.EndRequest;

            //
            return result;
        }