PHP.Core.ScriptContext.Include C# (CSharp) 메소드

Include() 공개 메소드

Includes a specific script using current configuration.
public Include ( string relativeSourcePath, bool once ) : object
relativeSourcePath string Source root relative path to the script.
once bool Specifies whether script should be included only once.
리턴 object
        public object Include(string/*!*/ relativeSourcePath, bool once)
        {
            ApplicationConfiguration app_config = Configuration.Application;

            // searches for file:
            FullPath included_full_path = SearchForIncludedFile(PhpError.Error, relativeSourcePath, FullPath.Empty);
            if (included_full_path.IsEmpty) return false;

            ScriptInfo info;
            bool already_included = scripts.TryGetValue(included_full_path.ToString(), out info);

            // skips inclusion if script has already been included and inclusion's type is "once":
            if (already_included)
            {
                if(once)
                    return ScriptModule.SkippedIncludeReturnValue;

                // script type loaded, info cannot be null
            }
            else
            {
                PhpSourceFile included_source_file = new PhpSourceFile(app_config.Compiler.SourceRoot, included_full_path);
                
                // loads script type:
                info = LoadDynamicScriptType(included_source_file);

                // script not found:
                if (info == null)
                    return false;

                if (MainScriptFile == null)
                    // the first script becomes the main one:
                    DefineMainScript(info, included_source_file);
                else
                    // adds included file into the script list
                    scripts.Add(included_full_path.ToString(), info);
            }

            Debug.Assert(info != null);

            return GuardedCall((ScriptInfo scriptInfo) =>
            {
                //return PhpScript.InvokeMainHelper(
                //    (Type)scriptType,
                return scriptInfo.Main(
                    this,
                    null,  // no local variables
                    null,  // no object context
                    null,  // no class context
                    true);
            }, info, true);
        }

Usage Example

        protected void Setup(ScriptContext c)
        {
            // Set a variable to the My Documents path.
            var section = (ClientSettingsSection)ConfigurationManager
                .GetSection("applicationSettings/wordpress.net.Properties.Settings");
            var settings = section.Settings;

            foreach (SettingElement setting in settings)
            {
                var value = setting.Value.ValueXml.InnerText;
                if (!string.IsNullOrWhiteSpace(value))
                {
                    c.DefineConstant(setting.Name, setting.Value.ValueXml.InnerText);
                }
                else
                {
                    switch (setting.Name)
                    {
                        case "ABSPATH":
                            var path = System.IO.Directory.GetParent(Server.MapPath("~")).Parent.FullName +
                                       "\\components\\WordPress\\";
                            c.DefineConstant("ABSPATH", path.Replace("\\", "/"));
                            break;
                    }
                }
            }

            /** Sets up WordPress vars and included files. */
            c.Include("..\\components\\WordPress\\wp-settings.php", true);
        }
All Usage Examples Of PHP.Core.ScriptContext::Include