Exemplo n.º 1
0
 /// <summary>
 /// Reads the currently executed file (a phar) and registers its manifest.
 /// </summary>
 /// <param name="ctx">Runtime context.</param>
 /// <param name="self">Current script.</param>
 /// <param name="alias">The alias that can be used in phar:// URLs to refer to this archive, rather than its full path.</param>
 /// <param name="dataoffset">Unused.</param>
 /// <returns>Always <c>true</c>.</returns>
 public static bool mapPhar(Context ctx, [ImportValue(ImportValueAttribute.ValueSpec.CallerScript)] RuntimeTypeHandle self, string alias = default, int dataoffset = 0)
 {
     if (PharExtensions.MapPhar(ctx, Type.GetTypeFromHandle(self), alias))
     {
         return(true);
     }
     else
     {
         throw new PharException();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Reads the currently executed file (a phar) and registers its manifest.
 /// </summary>
 /// <param name="ctx">Runtime context.</param>
 /// <param name="self">Current script.</param>
 /// <param name="alias">The alias that can be used in phar:// URLs to refer to this archive, rather than its full path.</param>
 /// <param name="dataoffset">Unused.</param>
 /// <returns>Always <c>true</c>.</returns>
 public static bool mapPhar(Context ctx, QueryValue <CallerScript> self, string alias = default, int dataoffset = 0)
 {
     if (PharExtensions.MapPhar(ctx, self.Value.ScriptType, alias))
     {
         return(true);
     }
     else
     {
         throw new PharException();
     }
 }
Exemplo n.º 3
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
                    }
                }
Exemplo n.º 4
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));
            }
Exemplo n.º 5
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);
            }
Exemplo n.º 6
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);