예제 #1
0
        public PhpHandlerMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, PhpRequestOptions options)
        {
            if (hostingEnv == null)
            {
                throw new ArgumentNullException(nameof(hostingEnv));
            }

            _next    = next ?? throw new ArgumentNullException(nameof(next));
            _options = options;

            // determine Root Path:
            _rootPath = hostingEnv.WebRootPath ?? hostingEnv.ContentRootPath ?? Directory.GetCurrentDirectory();

            if (!string.IsNullOrEmpty(options.RootPath))
            {
                _rootPath = Path.GetFullPath(Path.Combine(_rootPath, options.RootPath));  // use the root path option, relative to the ASP.NET Core Web Root
            }

            _rootPath = NormalizeRootPath(_rootPath);

            //

            // TODO: pass hostingEnv.ContentRootFileProvider to the Context for file system functions

            // sideload script assemblies
            LoadScriptAssemblies(options);
        }
예제 #2
0
 /// <summary>
 /// Loads and reflects assemblies containing compiled PHP scripts.
 /// </summary>
 static void LoadScriptAssemblies(PhpRequestOptions options)
 {
     if (options.ScriptAssembliesName != null)
     {
         foreach (var assname in options.ScriptAssembliesName.Select(str => new System.Reflection.AssemblyName(str)))
         {
             var ass = System.Reflection.Assembly.Load(assname);
             if (ass != null)
             {
                 Context.AddScriptReference(ass);
             }
             else
             {
                 LogEventSource.Log.ErrorLog($"Assembly '{assname}' couldn't be loaded.");
             }
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Loads and reflects assemblies containing compiled PHP scripts.
 /// </summary>
 static void LoadScriptAssemblies(PhpRequestOptions options)
 {
     if (options.ScriptAssembliesName != null)
     {
         foreach (var assname in options.ScriptAssembliesName.Select(str => new System.Reflection.AssemblyName(str)))
         {
             var ass = System.Reflection.Assembly.Load(assname);
             if (ass != null)
             {
                 Pchp.Core.Context.AddScriptReference(ass);
             }
             else
             {
                 Debug.Assert(false, $"Assembly '{assname}' couldn't be loaded.");
             }
         }
     }
 }
        public PhpHandlerMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, PhpRequestOptions options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (hostingEnv == null)
            {
                throw new ArgumentNullException(nameof(hostingEnv));
            }

            _next     = next;
            _options  = options;
            _rootPath = NormalizeRootPath(hostingEnv.WebRootPath ?? hostingEnv.ContentRootPath ?? System.IO.Directory.GetCurrentDirectory());
            // TODO: pass hostingEnv.ContentRootFileProvider to the Context for file system functions

            // sideload script assemblies
            LoadScriptAssemblies(options);
        }
 /// <summary>
 /// Installs request handler to compiled PHP scripts.
 /// </summary>
 public static IApplicationBuilder UsePhp(this IApplicationBuilder builder, PhpRequestOptions options = null)
 {
     return(builder.UseMiddleware <PhpHandlerMiddleware>(options ?? new PhpRequestOptions()));
 }