Esempio n. 1
0
        /// <summary>
        /// Evaluates the script with given Blazor context and render tree builder.
        /// </summary>
        public static PhpValue Evaluate(this Context.ScriptInfo script, BlazorContext ctx, Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder)
        {
            ctx.StartRender(builder);
            var result = script.Evaluate(ctx, ctx.Globals, null);

            ctx.StopRender();

            return(result);
        }
Esempio n. 2
0
 void InvokeAndDispose(RequestContextCore phpctx, Context.ScriptInfo script)
 {
     try
     {
         OnContextCreated(phpctx);
         phpctx.ProcessScript(script);
     }
     finally
     {
         phpctx.Dispose();
         phpctx.RequestCompletionSource.TrySetResult(RequestCompletionReason.Finished);
     }
 }
Esempio n. 3
0
        Task InvokeAndDispose(RequestContextCore phpctx, Context.ScriptInfo script)
        {
            try
            {
                OnContextCreated(phpctx);
                phpctx.ProcessScript(script);
            }
            finally
            {
                phpctx.Dispose();
                phpctx.RequestEndEvent?.Set();
            }

            //
            return(Task.CompletedTask);
        }
Esempio n. 4
0
            public override bool ResolveInclude(Context ctx, string cd, string path, out Context.ScriptInfo script)
            {
                // 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));
                        script = Context.TryGetDeclaredScript(pharPath);
                        return(script.IsValid);
                    }
                }

                // invalid
                script = default;
                return(false);
            }
Esempio n. 5
0
        async Task InvokeScriptAsync(HttpContext context, Context.ScriptInfo script, string path_info)
        {
            Debug.Assert(script.IsValid);

            using var phpctx = new RequestContextCore(context, _rootPath, _options.StringEncoding);

            OnContextCreated(phpctx);

            // run the script, dispose phpctx when finished
            // using threadpool since we have to be able to end the request and keep script running
            var task = Task.Run(() =>
            {
                try
                {
                    phpctx.ProcessScript(script, path_info);
                }
                finally
                {
                    phpctx.RequestCompletionSource.TrySetResult(RequestCompletionReason.Finished);
                }
            });

            // wait for the request to finish,
            // do not block current thread
            var reason = await phpctx.RequestCompletionSource.Task;

            if (task.Exception != null)
            {
                // rethrow script exception
                throw task.Exception;
            }
            else if (reason == RequestCompletionReason.Timeout)
            {
                throw RequestTimeoutException();
            }
        }
        private void Render(string ScriptName)
        {
            Context.ScriptInfo script = default;

            // If .php exists, it is a script, otherwise it is a component
            if (ScriptName.EndsWith(".php"))
            {
                script = Context.TryGetDeclaredScript(ScriptName);
            }

            if (!script.IsValid)
            {
                var segments = ScriptName.Split('/', StringSplitOptions.RemoveEmptyEntries);
                var result   = RouteManager.Match(segments);

                if (result.IsMatch)
                {
                    Log.ComponentNavigation(_logger, ScriptName);
                    _renderHandle.Render((builder) => {
                        builder.OpenComponent(0, result.MatchedRoute.Handler);
                        builder.AddAttribute(1, "Ctx", _ctx);
                        builder.CloseElement();
                    });
                }
                else
                {
                    Log.NavigationFailed(_logger, ScriptName);
                    _renderHandle.Render(NotFound);
                }
            }
            else
            {
                Log.ScriptNavigation(_logger, ScriptName);
                _renderHandle.Render((builder) => script.Evaluate(_ctx, builder));
            }
        }
Esempio n. 7
0
 public PhpContent(Context ctx, Context.ScriptInfo script, object @this)
 {
     _ctx    = ctx;
     _script = script;
     _this   = @this;
 }
Esempio n. 8
0
 /// <summary>
 /// Gets the type containing the script's main method.
 /// </summary>
 /// <remarks>The type or <c>null</c>.</remarks>
 public static Type GetScriptTypeFromScript(Context.ScriptInfo script) => script.GetScriptType();
Esempio n. 9
0
 public static CachedPhar TryGetCachedPhar(Context.ScriptInfo stubscript)
 {
     return(TryGetCachedPhar(ContextExtensions.GetScriptTypeFromScript(stubscript)));
 }