Beispiel #1
0
            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));
            }
Beispiel #2
0
            public override PhpStream Open(Context ctx, ref string path, string mode, StreamOpenOptions options, StreamContext context)
            {
                if (FileSystemUtils.TryGetScheme(path, out var schemespan))
                {
                    var schemeends = schemespan.Length + 3;
                    var sep        = path.IndexOfAny(PathUtils.DirectorySeparatorChars, schemeends);
                    if (sep >= 0)
                    {
                        Stream resource = null;

                        var alias    = path.Substring(schemeends, sep - schemeends);
                        var pharFile = PharExtensions.AliasToPharFile(ctx, alias);
                        if (pharFile != null)
                        {
                            // Template: phar://alias/entryName
                            resource = PharExtensions.GetResourceStream(pharFile, path.Substring(sep + 1));
                        }
                        else
                        {
                            // Template: phar://path_phar_file/entryName
                            var pharExt = path.IndexOfOrdinal(PharExtensions.PharExtension, schemeends, path.Length - schemeends);
                            if (pharExt >= 0 && pharExt + PharExtensions.PharExtension.Length + 1 < path.Length)
                            {
                                // path_phar_file:
                                var pharPath = path.Substring(schemeends, pharExt + PharExtensions.PharExtension.Length - schemeends);

                                // entryName:
                                var entryName = path.Substring(pharExt + PharExtensions.PharExtension.Length + 1);

                                // ensure phar is loaded
                                // TODO: locate pharPath and get containing System.Reflection.Assembly
                                throw new NotImplementedException();
                            }
                        }

                        if (resource != null)
                        {
                            return(new NativeStream(ctx, resource, this, StreamAccessOptions.UseText | StreamAccessOptions.Read, path, context));
                        }
                    }
                }

                return(null);
            }
Beispiel #3
0
            public Context.ScriptInfo ResolveScript(Context ctx, string cd, string path)
            {
                // Template: include "phar://{path}"

                var sep = path.IndexOfAny(PathUtils.DirectorySeparatorChars);

                if (sep >= 0)
                {
                    var pharFile = PharExtensions.AliasToPharFile(ctx, path.Remove(sep));
                    if (pharFile != null)
                    {
                        Debug.Assert(pharFile.EndsWith(PharExtensions.PharExtension, CurrentPlatform.PathStringComparison));
                        var pharPath = PharExtensions.PharEntryRelativePath(pharFile, path.Substring(sep + 1));
                        return(Context.TryGetDeclaredScript(pharPath));
                    }
                }

                // invalid
                return(default);