/// <summary> /// Gets phar content file stream. /// </summary> public static Stream GetResourceStream(CachedPhar phar, ReadOnlySpan <char> entryName) { var content = GetResourceContent(phar, entryName); if (content != null) { return(new MemoryStream(Encoding.UTF8.GetBytes(content))); } return(null); }
/// <summary> /// Gets phar content. /// </summary> public static string GetResourceContent(CachedPhar phar, ReadOnlySpan <char> entryName) { if (phar != null && phar.Resources != null) { // TODO: the resource should be embedded as Stream // return value may change from string to Stream return(phar.Resources.GetString(entryName.ToString().Replace('\\', '/'))); } return(null); }
static bool TryResolvePhar(Context ctx, ReadOnlySpan <char> path, out CachedPhar phar, out ReadOnlySpan <char> entry) { return(TryResolvePhar(pharpath => { var result = PharExtensions.AliasToPharFile(ctx, pharpath); if (result == null && pharpath.EndsWith(PharExtensions.PharExtension, CurrentPlatform.PathStringComparison)) { // resolve not-mapped phars (resolve path to root ... find .phar in compiled scripts ...) var stub = Context.TryResolveScript(ctx.RootPath, pharpath); result = PharExtensions.TryGetCachedPhar(stub); } return result; }, path, out phar, out entry)); }
static CachedPhar EnsureCachedPhar(Type stubScriptType) { CachedPhar cached = null; var pharFile = GetPharFile(stubScriptType); if (pharFile != null) { var cachedPhars = _cachedPhars; if (cachedPhars == null || !cachedPhars.TryGetValue(pharFile, out cached)) { var newdict = cachedPhars != null ? new Dictionary <string, CachedPhar>(cachedPhars, CurrentPlatform.PathComparer) : new Dictionary <string, CachedPhar>(CurrentPlatform.PathComparer); newdict[pharFile] = cached = new CachedPhar(stubScriptType); _cachedPhars = newdict; } } return(cached); }
static bool TryResolvePhar(Func <string, CachedPhar> resolver, ReadOnlySpan <char> path, out CachedPhar phar, out ReadOnlySpan <char> entry) { phar = default; entry = default; if (FileSystemUtils.TryGetScheme(path, out var schemespan)) { if (!schemespan.SequenceEqual("phar".AsSpan())) { return(false); } // slice off the scheme:// path = path.Slice(schemespan.Length + 3); } if (path.IsEmpty) { return(false); } // find the phar for (int slash = 0; slash <= path.Length; slash++) { if (slash == path.Length || PathUtils.IsDirectorySeparator(path[slash])) { var pharpath = path.Slice(0, slash); phar = resolver(pharpath.ToString()); if (phar != null) { entry = slash < path.Length ? path.Slice(slash + 1) : ReadOnlySpan <char> .Empty; return(true); } } } // return(false); }