/// <summary> /// Initializes the script context for a web request. /// </summary> /// <param name="appContext">Application context.</param> /// <param name="context">HTTP context of the request.</param> /// <returns>A instance of <see cref="ScriptContext"/> to be used by the request.</returns> /// <exception cref="System.Configuration.ConfigurationErrorsException"> /// Web configuration is invalid. The context is not initialized then. /// </exception> internal static ScriptContext/*!*/ InitWebRequest(ApplicationContext/*!*/ appContext, HttpContext/*!*/ context) { Debug.Assert(appContext != null && context != null); // reloads configuration of the current thread from ASP.NET caches or web.config files; // cached configuration is reused; Configuration.Reload(appContext, false); // takes a writable copy of a global configuration (may throw ConfigurationErrorsException): LocalConfiguration config = (LocalConfiguration)Configuration.DefaultLocal.DeepCopy(); // following initialization statements shouldn't throw an exception: // can throw on Integrated Pipeline, events must be attached within HttpApplication.Init() ScriptContext result = new ScriptContext(appContext, config, context.Response.Output, context.Response.OutputStream); result.IsOutputBuffered = config.OutputControl.OutputBuffering; result.ThrowExceptionOnError = true; result.WorkingDirectory = Path.GetDirectoryName(context.Request.PhysicalPath); if (config.OutputControl.ContentType != null) context.Response.ContentType = config.OutputControl.ContentType; if (config.OutputControl.CharSet != null) context.Response.Charset = config.OutputControl.CharSet; result.AutoGlobals.Initialize(config, context); ScriptContext.CurrentContext = result; Externals.BeginRequest(); return result; }
/// <summary> /// Creates an instance of the manager. /// </summary> internal ApplicationCompilerManager(ApplicationContext applicationContext, PhpAssemblyBuilder/*!*/ assemblyBuilder) { Debug.Assert(assemblyBuilder != null); Debug.Assert(applicationContext != null); this.successful = true; this.assemblyBuilder = assemblyBuilder; this.applicationContext = applicationContext; }
/* /// <summary> /// Severity of inclusion-related errors. This is determined by type of inclusion being made and is needed by subsequent functions to report errors. /// </summary> public PhpError ErrorSeverity { get { return errorSeverity; } } private PhpError errorSeverity; */ public InclusionResolutionContext(ApplicationContext applicationContext, string scriptDirectory, string workingDirectory, string searchPaths) { Debug.Assert(applicationContext != null && scriptDirectory != null && workingDirectory != null && searchPaths != null); this.applicationContext = applicationContext; this.scriptDirectory = scriptDirectory; this.workingDirectory = workingDirectory; this.searchPaths = searchPaths; }
/// <summary> /// Creates a compilation context. /// </summary> /// <param name="applicationContext">Application context.</param> /// <param name="manager">Manager.</param> /// <param name="config">Configuration.</param> /// <param name="errorSink">Error sink.</param> /// <param name="workingDirectory">Working directory.</param> internal CompilationContext(ApplicationContext/*!*/ applicationContext, ICompilerManager manager, CompilerConfiguration/*!*/ config, ErrorSink/*!*/ errorSink, string/*!*/ workingDirectory) { Debug.Assert(applicationContext != null); Debug.Assert(config != null && workingDirectory != null); this.applicationContext = applicationContext; this.manager = manager; this.config = config; this.errors = errorSink; this.workingDirectory = workingDirectory; }
/// <summary> /// Loads compiler configuration values from a specified .config file into a given record. /// </summary> /// <param name="appContext">Application context where to load libraries.</param> /// <param name="path">A full path to the .config file.</param> /// <returns>The new configuration record.</returns> /// <exception cref="ConfigurationErrorsException">An error in configuration.</exception> public void LoadFromFile(ApplicationContext/*!*/ appContext, FullPath path) { if (appContext == null) throw new ArgumentNullException("appContext"); path.EnsureNonEmpty("path"); ConfigXmlDocument doc = new ConfigXmlDocument(); try { doc.Load(path); } catch (XmlException e) { throw new ConfigurationErrorsException(e.Message); } XmlNode root = doc.DocumentElement; if (root.Name == "configuration") { ProcessNodes(appContext, root, addedLibraries); } }
/// <summary> /// Load class libraries collected while parsing configuration files. /// </summary> /// <param name="appContext"></param> internal void LoadLibraries(ApplicationContext/*!*/ appContext) { addedLibraries.LoadLibrariesNoLock( (_assemblyName, _assemblyUrl, _sectionName, /*!*/ _node) => { appContext.AssemblyLoader.Load(_assemblyName, _assemblyUrl, new LibraryConfigStore(_node)); return true; }, null // ignore class library sections ); }
/// <summary> /// Loads configuration and returns configuration record. /// </summary> /// <exception cref="ConfigurationErrorsException">Configuration is invalid or incomplete.</exception> public static void Load(ApplicationContext/*!*/ appContext) { if (current == null) { Debug.Assert(!isBeingLoadedToCurrentThread, "Configuration loader triggered next configuration load"); isBeingLoadedToCurrentThread = true; try { PhpConfigurationContext context = ConfigurationSectionHandler.GetConfig(appContext, SectionName); if (context != null) { current = new Configuration(context.Global, context.Local); } else { // no configuration loaded from .config files: current = new Configuration(new GlobalConfiguration(), new LocalConfiguration()); } } finally { isBeingLoadedToCurrentThread = false; } } }
/// <summary> /// Makes a copy (child) of this instance (parent) deeply copying the confgiuration fields. /// </summary> internal PhpConfigurationContext(ApplicationContext/*!*/ applicationContext, string virtualPath, PhpConfigurationContext parent) { Debug.Assert(applicationContext != null); this.virtualPath = virtualPath; this.applicationContext = applicationContext; // section tables are shared: this.sections = parent.sections; this.sealedSections = parent.sealedSections; this.librariesList = parent.librariesList; // configuration records are copied: this.local = (LocalConfiguration)parent.local.DeepCopy(); this.global = (GlobalConfiguration)parent.global.DeepCopy(); }
/// <summary> /// Creates an instance of of multi-script assembly builder. /// </summary> /// <param name="applicationContext">Application context.</param> /// <param name="assemblyName">Name of the assembly.</param> /// <param name="directory">Directory where assembly will be stored.</param> /// <param name="fileName">Name of the assembly file including an extension.</param> /// <param name="kind">Assembly file kind.</param> /// <param name="debug">Whether to include debug information.</param> /// <param name="force32bit">Whether to force 32bit execution of generated assembly.</param> /// <param name="entryPoint">Entry point.</param> /// <param name="icon">Icon.</param> /// <param name="resources">Resources to embed</param> public MultiScriptAssemblyBuilder(ApplicationContext/*!*/ applicationContext, AssemblyName assemblyName, string directory, string fileName, AssemblyKinds kind, ICollection<ResourceFileReference> resources, bool debug, bool force32bit, Win32IconResource icon, PhpSourceFile entryPoint) : base(new MultiScriptAssembly(applicationContext), assemblyName, directory, fileName, kind, resources, debug, force32bit, false, icon) { this.entryPoint = entryPoint; }
/// <summary> /// Creates a new instance of the manager. /// Manager can be instantiated either in dedicated domain or in web AppDomain. /// </summary> /// <param name="appContext">Application context.</param> public WebServerCompilerManager(ApplicationContext/*!*/ appContext) { Debug.Assert(appContext != null); bool isWebApp = HttpContext.Current != null; // whether we are running web app or an executable app this.outDir = isWebApp ? HttpRuntime.CodegenDir : Path.GetTempPath(); this.events = new Dictionary<PhpSourceFile, ManualResetEvent>(); this.applicationContext = appContext; // On Windows it's case-insensitive, because same file can be accessed with various cases cache = new Dictionary<string, CacheEntry>(100, FullPath.StringComparer); // install file system watcher to invalidate cache of files that have been modified: if (isWebApp && Configuration.Application.Compiler.WatchSourceChanges && !Configuration.Application.Compiler.OnlyPrecompiledCode) { watcher = new FileSystemWatcher() { // TODO: multiple paths (multiple watchers?): Path = Configuration.Application.Compiler.SourceRoot.ToString(), NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite, IncludeSubdirectories = true, EnableRaisingEvents = false, }; watcher.Changed += OnFileChanged; watcher.Renamed += OnFileRenamed; watcher.Deleted += OnFileChanged; } else { watcher = null; } // look for "App_Code.compiled" file if (isWebApp) LoadAppCode(Path.Combine(HttpRuntime.CodegenDir, "App_Code.compiled")); }
/// <summary> /// Loads configuration and returns configuration record. /// </summary> /// <exception cref="ConfigurationErrorsException">Configuration is invalid or incomplete.</exception> public static void Load(ApplicationContext/*!*/ appContext) { if (current == null) { // no configuration loaded from .config files: current = new Configuration(new GlobalConfiguration(), new LocalConfiguration()); } }
/// <summary> /// Creates and initializes request and script contexts associated with the current thread. /// </summary> /// <param name="appContext">Application context.</param> /// <param name="context">Current HTTP context.</param> /// <returns>The initialized request context.</returns> /// <remarks> /// <para> /// Request context provides PHP with the web server environment. /// It should be initialized before any PHP code is invoked within web server and finalized (disposed) /// at the end of the request. This method can be called for multiple times, however it creates and /// initializes a new request context only once per HTTP request. /// </para> /// <para> /// The following steps take place during the initialization (in this order): /// <list type="number"> /// <term>Configuration is loaded (if not loaded yet).</term> /// <term>A new instance of <see cref="RequestContext"/> is created and bound to the current thread.</term> /// <term>A new instance of <see cref="ScriptContext"/> is created and initialized.</term> /// <term>Event <see cref="RequestBegin"/> is fired.</term> /// <term>Session is started if session auto-start confgiuration option is switched on.</term> /// </list> /// </para> /// <para> /// The request context can be accessed via the returned instance or via <see cref="CurrentContext"/> /// thread static field anytime between the initialization and disposal. /// </para> /// </remarks> public static RequestContext/*!*/ Initialize(ApplicationContext/*!*/ appContext, HttpContext/*!*/ context) { if (appContext == null) throw new ArgumentNullException("appContext"); if (context == null) throw new ArgumentNullException("context"); RequestContext req_context = currentContext; // already initialized within the current request: if (req_context != null && req_context.httpContext.Timestamp == context.Timestamp) return req_context; Debug.WriteLine("REQUEST", "-- started ----------------------"); req_context = new RequestContext(context); currentContext = req_context; req_context.Initialize(appContext); return req_context; }
/// <summary> /// Initializes the context. /// </summary> private void Initialize(ApplicationContext/*!*/ appContext) { Debug.Assert(appContext != null); defaultResponseEncoding = httpContext.Response.ContentEncoding; scriptContext = ScriptContext.InitWebRequest(appContext, httpContext); TrackClientDisconnection = !scriptContext.Config.RequestControl.IgnoreUserAbort; // Session is ended after destructing objects since PHP 5.0.5, use two-phase finalization: scriptContext.TryDispose += () => { this.TryDisposeBeforeFinalization(); // ends session // finalize objects created during session closing and output finalization: this.scriptContext.GuardedCall<object, object>(this.scriptContext.FinalizePhpObjects, null, false); // Platforms-specific dispose this.TryDisposeAfterFinalization(); // flushes headers }; // Platforms-specific finally dispose scriptContext.FinallyDispose += FinallyDispose; // if (RequestBegin != null) RequestBegin(); }
public static PhpAssemblyBuilder/*!*/ Create(ApplicationContext/*!*/ applicationContext, AssemblyKinds kind, bool pure, FullPath outPath, FullPath docPath, string duckPath, string duckNs, PhpSourceFile entryPoint, Version version, StrongNameKeyPair key, Win32IconResource icon, ICollection<ResourceFileReference> resources, bool debug) { string out_dir = Path.GetDirectoryName(outPath); string out_file = Path.GetFileName(outPath); AssemblyName assembly_name = new AssemblyName(); assembly_name.Name = Path.GetFileNameWithoutExtension(outPath); assembly_name.Version = version; assembly_name.KeyPair = key; if (pure) { // This is primarilly supported for non-pure mode, but it could be extended.. if (duckPath != null) throw new NotSupportedException("Generation of duck type interfaces isn't supported for pure assemblies!"); return new PureAssemblyBuilder(applicationContext, assembly_name, out_dir, out_file, kind, resources, debug, icon); } else return new MultiScriptAssemblyBuilder(applicationContext, assembly_name, out_dir, out_file, duckPath, duckNs, kind, resources, debug, icon, entryPoint); }
/// <summary> /// Creates new ScriptLibraryDatabase object. /// </summary> /// <param name="context">Owning application context.</param> public ScriptLibraryDatabase(ApplicationContext context) { applicationContext = context; }
public PureAssemblyBuilder(ApplicationContext/*!*/ applicationContext, AssemblyName assemblyName, string directory, string fileName, AssemblyKinds kind, ICollection<ResourceFileReference> resources, bool debug, bool force32bit, Win32IconResource icon) : base(new PureAssembly(applicationContext), assemblyName, PureAssembly.ModuleName, directory, fileName, kind, resources, debug, force32bit, false, icon) { }
/// <summary> /// Creates an instance of of single-script assembly builder (without resources). /// </summary> /// <param name="applicationContext">Application context.</param> /// <param name="assemblyName">Name of the assembly.</param> /// <param name="directory">Directory where assembly will be stored.</param> /// <param name="fileName">Name of the assembly file including an extension.</param> /// <param name="kind">Assembly kind.</param> /// <param name="debug">Whether to include debug information.</param> /// <param name="force32bit">Whether to force 32bit execution of generated assembly.</param> /// <param name="saveOnlyAssembly">Whether to not load the assembly into memory.</param> /// <param name="icon">Icon resource or a <B>null</B> reference.</param> public SingleScriptAssemblyBuilder(ApplicationContext/*!*/ applicationContext, AssemblyName assemblyName, string directory, string fileName, AssemblyKinds kind, bool debug, bool force32bit, bool saveOnlyAssembly, Win32IconResource icon) : base(new SingleScriptAssembly(applicationContext), assemblyName, directory, fileName, kind, null, debug, force32bit, saveOnlyAssembly, icon) { }
public WebCompilationContext(ApplicationContext applicationContext, ICompilerManager/*!*/ manager, CompilerConfiguration/*!*/ config, string/*!*/ workingDirectory, DateTime requestTimestamp) : base(applicationContext, manager, config, new WebErrorSink(config.Compiler.DisabledWarnings, config.Compiler.DisabledWarningNumbers), workingDirectory) { this.requestTimestamp = requestTimestamp; }
/// <summary> /// Initializes the script context for a PHP console application. /// </summary> /// <param name="appContext">Application context.</param> /// <param name="mainScript">The main script's type or a <B>null</B> reference for a pure application.</param> /// <param name="relativeSourcePath">A path to the main script source file.</param> /// <param name="sourceRoot">A source root within which an application has been compiler.</param> /// <returns> /// A new instance of <see cref="ScriptContext"/> with its own copy of local configuration /// to be used by the application. /// </returns> /// <exception cref="System.Configuration.ConfigurationErrorsException"> /// Web configuration is invalid. The context is not initialized then. /// </exception> /// <remarks> /// 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: /// <list type="bullet"> /// <term>The application's source root is set.</term> /// <term>The main script of the application is defined.</term> /// <term>Output and input streams are set to standard output and input, respectively.</term> /// <term>Current culture it set to <see cref="CultureInfo.InvariantCulture"/>.</term> /// <term>Auto-global variables ($_GET, $_SET, etc.) are initialized.</term> /// <term>Working directory is set tothe current working directory.</term> /// </list> /// </remarks> 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(); return result; }
/// <summary> /// Compiles an application. /// </summary> /// <param name="applicationContext">Application context.</param> /// <param name="config">Compiler configuration record.</param> /// <param name="errorSink">Error sink.</param> /// <param name="ps">Parameters.</param> /// <exception cref="InvalidSourceException">Cannot read a source file/directory. See the inner exception for details.</exception> public void Compile( ApplicationContext/*!*/ applicationContext, CompilerConfiguration/*!*/ config, ErrorSink/*!*/ errorSink, CompilationParameters/*!*/ ps) { if (applicationContext == null) throw new ArgumentNullException("applicationContext"); if (config == null) throw new ArgumentNullException("config"); if (errorSink == null) throw new ArgumentNullException("errorSink"); ps.Validate(); PhpSourceFile entry_point_file = (ps.StartupFile != null) ? new PhpSourceFile(config.Compiler.SourceRoot, ps.StartupFile) : null; List<ResourceFileReference> resource_files = ResourceFileReference.FromFiles(ps.Resources); // creates directory if not exists: try { Directory.CreateDirectory(Path.GetDirectoryName(ps.OutPath)); } catch (Exception ex) { errorSink.Add(FatalErrors.ErrorCreatingFile, null, ErrorPosition.Invalid, ps.OutPath, ex.Message); } AssemblyKinds kind; switch (ps.Target) { case Targets.Dll: kind = AssemblyKinds.Library; entry_point_file = null; break; case Targets.Console: kind = AssemblyKinds.ConsoleApplication; break; case Targets.WinApp: kind = AssemblyKinds.WindowApplication; break; case Targets.Web: kind = AssemblyKinds.WebPage; entry_point_file = null; break; default: throw new ArgumentException(); } PhpAssemblyBuilder assembly_builder = PhpAssemblyBuilder.Create(applicationContext, kind, ps.Pure, ps.OutPath, ps.DocPath, entry_point_file, ps.Version, ps.Key, ps.Icon, resource_files, config.Compiler.Debug, ps.Force32Bit); assembly_builder.IsMTA = ps.IsMTA; Statistics.CompilationStarted(); ICompilerManager manager = (!ps.Pure) ? new ApplicationCompilerManager(applicationContext, assembly_builder) : null; try { CompilationContext context = new CompilationContext(applicationContext, manager, config, errorSink, config.Compiler.SourceRoot); assembly_builder.Build(EnumerateScripts(ps.SourcePaths, ps.SourceDirs, ps.FileExtensions, context), context); if (!context.Errors.AnyError && (ps.Target == Targets.Console || ps.Target == Targets.WinApp)) CopyApplicationConfigFile(config.Compiler.SourceRoot, ps.OutPath); } catch (CompilerException e) { errorSink.Add(e.ErrorInfo, null, ErrorPosition.Invalid, e.ErrorParams); } catch (InvalidSourceException e) { e.Report(errorSink); } catch (Exception e) { #if DEBUG //Console.WriteLine("Unexpected error: {0}", e.ToString());// removed, exception added into the error sink, so it's displayed in the VS Integration too #endif errorSink.AddInternalError(e); // compilation will fail, error will be displayed in Errors by VS Integration } finally { #if DEBUG Console.WriteLine(); Console.WriteLine("Statistics:"); Statistics.Dump(Console.Out, Path.GetDirectoryName(ps.OutPath)); Console.WriteLine(); #endif } }
/// <summary> /// Creates an empty configuration context used as a root context. /// </summary> internal PhpConfigurationContext(ApplicationContext/*!*/ applicationContext, string virtualPath) { Debug.Assert(applicationContext != null); this.virtualPath = virtualPath; this.applicationContext = applicationContext; this.sections = new Dictionary<string, LibrarySection>(); this.sealedSections = new Dictionary<string, string>(); this.librariesList = new LibrariesConfigurationList(); this.local = new LocalConfiguration(); this.global = new GlobalConfiguration(); }
/// <summary> /// Loads configuration from Machine.config, phpc.exe.config, from files specified by command line arguments, /// and from command line arguments themselves. /// </summary> /// <exception cref="ConfigurationErrorsException">An error occured while loading the configuration.</exception> public static CompilerConfiguration/*!*/ LoadConfiguration( ApplicationContext/*!*/ appContext, List<FullPath>/*!*/ paths, TextWriter output) { Configuration.IsBuildTime = true; Configuration.Reload(appContext, true); // Machine.config, phpc.exe.config: CompilerConfiguration result = new CompilerConfiguration(Configuration.Application); // explicitly specified or default configs: foreach (FullPath path in paths) { if (output != null) output.WriteLine(path); result.LoadFromFile(appContext, path); } // load libraries lazily result.LoadLibraries(appContext); // return result; }
/// <summary> /// Gets a configuration context from the ASP.NET cache. /// </summary> internal static PhpConfigurationContext GetConfig(ApplicationContext/*!*/ appContext, string/*!*/ sectionName) { Debug.Assert(appContext != null); PhpConfigurationContext context; lock (loadMutex) { applicationContext = appContext; int old_stamp = stamp; // loads configuration from all relevant .config files using our Configuration Section Handler; // although this way of loading configuration is considered deprecated, the new one is not feasible: #pragma warning disable 618 context = (PhpConfigurationContext)ConfigurationManager.GetSection(sectionName); //ConfigurationSettings.GetConfig(sectionName); #pragma warning restore 618 int new_stamp = stamp; if (new_stamp != old_stamp) { // a new context has been loaded from .config file // // fills in missing configuration and checks whether the configuration has been loaded properly: if (context != null) { context.LoadLibrariesNoLock(); context.ValidateNoLock(); } // validates application configuration if it has not been validated yet; // the application configuration is shared among all requests (threads); // therefore only the first one should validate it: Configuration.application.ValidateNoLock(); } } return context; }
/// <summary> /// Creates an instance of of single-script assembly builder. /// </summary> /// <param name="applicationContext">Application context.</param> /// <param name="assemblyName">Name of the assembly.</param> /// <param name="directory">Directory where assembly will be stored.</param> /// <param name="fileName">Name of the assembly file including an extension.</param> /// <param name="kind">Assembly kind.</param> /// <param name="debug">Whether to include debug information.</param> /// <param name="force32bit">Whether to force 32bit execution of generated assembly.</param> /// <param name="saveOnlyAssembly">Whether to not load the assembly into memory.</param> /// <param name="icon">Icon resource or a <B>null</B> reference.</param> /// <param name="resources">Resources to embed</param> public SingleScriptAssemblyBuilder(ApplicationContext/*!*/ applicationContext, AssemblyName assemblyName, string directory, string fileName, AssemblyKinds kind, ICollection<ResourceFileReference> resources, DebugMode debug, bool force32bit, bool saveOnlyAssembly, Win32IconResource icon) : base(new SingleScriptAssembly(applicationContext), assemblyName, directory, fileName, kind, resources, debug, force32bit, saveOnlyAssembly, icon) { }
/// <summary> /// Drops the configuration associated with the current thread and loads a new one. /// Doesn't reload XML data from file (cached configuration records are reused). /// The libraries listed in the <c>classLibrary</c> section are therefore not loaded into the context. /// </summary> /// <remarks> /// The current thread may have been reused to serve a different request with different configuration context. /// Therefore, the configuration associated with the thread needs to be dropped and a new one to be loaded. /// </remarks> public static void Reload(ApplicationContext/*!*/ appContext, bool reloadFromFile) { current = null; if (reloadFromFile) ConfigurationManager.RefreshSection(SectionName); Load(appContext); }
/// <summary> /// Initializes <see cref="ScriptContext"/> for the C#/PHP interoperability. /// </summary> /// <param name="appContext">Application context.</param> /// <returns>New <see cref="ScriptContext"/></returns> /// <remarks> /// Use this method if you want to initialize application in the same way the PHP console/Windows /// application is initialized. CurrentContext is set, and initialized to simulate request begin and end. /// </remarks> public static ScriptContext/*!*/InitContext(ApplicationContext appContext) { if (appContext == null) appContext = ApplicationContext.Default; var context = InitApplication(appContext, null, null, null); // simulate request lifecycle RequestContext.InvokeRequestBegin(); context.FinallyDispose += RequestContext.InvokeRequestEnd; // return context; }
/// <summary> /// Parses a XML node and loads the configuration values from it. /// </summary> /// <param name="applicationContext">Context where to load libraries.</param> /// <param name="section">The "phpNet" section node.</param> /// <param name="addedLibraries">List of class libraries to be loaded lazily.</param> internal void Parse(ApplicationContext/*!*/ applicationContext, XmlNode/*!*/ section, LibrariesConfigurationList/*!*/addedLibraries) { // parses XML tree: foreach (XmlNode node in section.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { switch (node.Name) { case ConfigurationSectionHandler.NodeClassLibrary: ConfigUtils.ParseLibraryAssemblyList( node, addedLibraries, Paths.ExtWrappers, Paths.Libraries); break; case ConfigurationSectionHandler.NodeScriptLibrary: ConfigUtils.ParseScriptLibraryAssemblyList(node, applicationContext.ScriptLibraryDatabase); break; case ConfigurationSectionHandler.NodeCompiler: ConfigUtils.ParseNameValueList(node, null, Compiler); break; case ConfigurationSectionHandler.NodeGlobalization: ConfigUtils.ParseNameValueList(node, null, Globalization); break; } } } }
/// <summary> /// Initializes <see cref="ScriptContext"/> for the C#/PHP interoperability. /// </summary> /// <param name="appContext">Application context.</param> /// <param name="output">Output stream.</param> /// <returns>New <see cref="ScriptContext"/></returns> /// <remarks> /// Use this method if you want to initialize application in the same way the PHP console/Windows /// application is initialized. CurrentContext is set, and initialized to simulate request begin and end. /// </remarks> public static ScriptContext/*!*/InitContext(ApplicationContext appContext, Stream output) { var context = InitContext(appContext); // setups output if (output == null) output = Stream.Null; context.OutputStream = output; context.Output = new StreamWriter(output); return context; }
/// <summary> /// Recursively handles loading of the configuration file sections, to handle the inheritance properly /// </summary> /// <param name="appContext">Application context where to load libraries.</param> /// <param name="root">Root to parse child nodes from</param> /// <param name="addedLibraries">List of class libraries that are collected while parsing configuration node.</param> private void ProcessNodes(ApplicationContext appContext, XmlNode root, LibrariesConfigurationList/*!*/addedLibraries) { foreach (XmlNode node in root.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { switch (node.Name) { case Configuration.SectionName: Parse(appContext, node, addedLibraries); break; case Configuration.LocationName: // Recursively parse the Web.config file to include everything in the <location> element ProcessNodes(appContext, node, addedLibraries); break; case "system.web": ParseSystemWebSection(node); break; } } } }
public static PhpAssemblyBuilder/*!*/ Create(ApplicationContext/*!*/ applicationContext, AssemblyKinds kind, bool pure, FullPath outPath, FullPath docPath, PhpSourceFile entryPoint, Version version, StrongNameKeyPair key, Win32IconResource icon, ICollection<ResourceFileReference> resources, bool debug, bool force32bit) { string out_dir = Path.GetDirectoryName(outPath); string out_file = Path.GetFileName(outPath); AssemblyName assembly_name = new AssemblyName(); assembly_name.Name = Path.GetFileNameWithoutExtension(outPath); assembly_name.Version = version; assembly_name.KeyPair = key; if (pure) { return new PureAssemblyBuilder(applicationContext, assembly_name, out_dir, out_file, kind, resources, debug, force32bit, icon); } else { return new MultiScriptAssemblyBuilder(applicationContext, assembly_name, out_dir, out_file, kind, resources, debug, force32bit, icon, entryPoint); } }