/// <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); } }
public PhpTypeInfo?AutoloadByTypeNameFromClassMap(string fullName, bool onlyAllowed) { if (fullName == null) { throw new ArgumentNullException(nameof(fullName)); } if (fullName.Length != 0 && fullName[0] == Utilities.PhpClassName.NamespaceSeparator) { fullName = fullName.Substring(1); } if (s_typeMap.TryGetType(fullName, out var tinfo, out var autoload) && tinfo != null) { if (onlyAllowed && autoload == 0) { // type was not marked as to be autoloaded return(null); } if (autoload == PhpTypeAttribute.AutoloadAllowNoSideEffect) { _types.DeclareType(tinfo); return(tinfo); } else { var script = ScriptsMap.GetDeclaredScript(tinfo.RelativePath); // pretend we are PHP and include the script: if (script.IsValid && !_scripts.IsIncluded(script.Index)) // include_once: { script.Evaluate(this, this.Globals, null); return(GetDeclaredType(fullName, autoload: false)); } } } return(null); }
/// <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); }
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); }
public static ScriptInfo ResolveScript(HttpRequest req) { var path = req.Path.Value.Replace('/', '\\').Trim('\\'); // TODO: normalized form return(ScriptsMap.GetDeclaredScript(path)); }
public static ScriptInfo TryGetDeclaredScript(string relpath) => ScriptsMap.GetDeclaredScript(relpath);
//static ScriptInfo DefaultDocument //{ // get // { // if (_lazyDefaultDocument.HasValue) // { // return _lazyDefaultDocument.Value; // } // _lazyDefaultDocument = ScriptsMap.GetDeclaredScript("index.php"); // return _lazyDefaultDocument.Value; // } //} //static ScriptInfo? _lazyDefaultDocument; public static ScriptInfo ResolveScript(HttpRequest req) { var path = req.Path.Value.Trim('\\', '/'); // TODO return(ScriptsMap.GetDeclaredScript(path)); }