Exemple #1
0
            public override PhpStream Open(Context ctx, ref string path, string mode, StreamOpenOptions options, StreamContext context)
            {
                if (TryResolvePhar(ctx, path.AsSpan(), out var phar, out var entry))
                {
                    // Template: phar://alias/entryName
                    var resource = PharExtensions.GetResourceStream(phar, entry);

                    if (resource != null)
                    {
                        return(new NativeStream(ctx, resource, this, StreamAccessOptions.UseText | StreamAccessOptions.Read, path, context));
                    }
                    else
                    {
                        // TODO: entry not found
                    }
                }
Exemple #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);
            }