Document IPHPService.cs, PHPModule.cs, and PHPService.cs methods

This commit is contained in:
Tomas Husak 2021-07-15 15:32:47 +02:00
Родитель b075d6c513
Коммит 41bd60dd8b
5 изменённых файлов: 57 добавлений и 3 удалений

Просмотреть файл

@ -17,6 +17,7 @@ namespace Peachpie.Blazor
/// Writes the content to <see cref="PhpTreeBuilder"/>.
/// </summary>
/// <param name="ctx">The <see cref="BlazorContext"/>.</param>
/// <param name="builder">Actual builder derived from the original tree builder obtained from the renderer.</param>
/// <param name="startIndex">The next sequence number used by Blazor diff algorithm.</param>
/// <returns>Returns the next sequence number after the written content.</returns>
public int writeWithTreeBuilder(Context ctx, PhpTreeBuilder builder, int startIndex);

Просмотреть файл

@ -6,7 +6,7 @@ using System;
namespace Peachpie.Blazor
{
/// <summary>
/// The class is a wrapper of <see cref="Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder">. It helps to call all Blazor API from PHP.
/// The class is a wrapper of <see cref="Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder"/>. It helps to call all Blazor API from PHP.
/// </summary>
[PhpType]
public class PhpTreeBuilder

Просмотреть файл

@ -11,12 +11,26 @@ namespace Peachpie.Blazor
/// </summary>
public interface IPHPService : IDisposable
{
/// <summary>
/// Gets a js module providing supporting functions for Peachpie.Blazor.
/// </summary>
public PHPModule GetModule();
/// <summary>
/// Gets a context set by <see cref="PhpScriptProvider"/> or <see cref="PhpComponent"/>.
/// </summary>
/// <returns>Null, if the context has not been set else <see cref="BlazorContext"/></returns>
public BlazorContext GetActualContext();
/// <summary>
/// Creates a new context, which is set as the actual context of the session.
/// </summary>
/// <returns></returns>
public BlazorContext CreateNewContext();
/// <summary>
/// Initializes PHPModule (imports phpModule.js from the server).
/// </summary>
public Task InitializePHPModuleAsync();
}
}

Просмотреть файл

@ -7,6 +7,9 @@ using System.Threading.Tasks;
namespace Peachpie.Blazor
{
/// <summary>
/// Represents the API of phpModule.js providing support functions for Peachpie.Blazor
/// </summary>
public class PHPModule : IDisposable
{
#region JS function names
@ -27,7 +30,6 @@ namespace Peachpie.Blazor
private const string _modulePath = "./_content/Peachpie.Blazor/phpModule.js";
private IJSInProcessObjectReference _moduleRef;
private bool _initialized = false;
private DotNetObjectReference<BlazorContext> _ctxRef;
@ -39,9 +41,11 @@ namespace Peachpie.Blazor
private void Initialize()
{
_moduleRef.InvokeVoid(_initializeCommand);
_initialized = true;
}
/// <summary>
/// Imports phpModule.js from the server and initializes it.
/// </summary>
public static async Task<PHPModule> CreateAsync(IJSRuntime jsRuntime)
{
var module = await (jsRuntime as IJSInProcessRuntime).InvokeAsync<IJSInProcessObjectReference>(_importCommand, _modulePath);
@ -57,6 +61,9 @@ namespace Peachpie.Blazor
#region Module exports
/// <summary>
/// Sets the context in js runtime, where can be used for calling PHP methods from JS.
/// </summary>
public void SetPHPContext(BlazorContext ctx)
{
_ctxRef?.Dispose();
@ -65,22 +72,51 @@ namespace Peachpie.Blazor
_moduleRef.InvokeVoid(_setPHPContextCommand, _ctxRef);
}
/// <summary>
/// Checks if a form with the post method was submited.
/// </summary>
public bool IsPostRequest() => _moduleRef.Invoke<bool>(_isPostRequestedCommand);
/// <summary>
/// Checks if a form containing files was submited.
/// </summary>
public bool isFilesPresented() => _moduleRef.Invoke<bool>(_isFilesPresentedCommand);
/// <summary>
/// Turns forms to submit data on a client side. It is handled by Blazor.
/// </summary>
public void TurnFormsToClientSide() => _moduleRef.InvokeVoid(_changeFormsCommand);
/// <summary>
/// Gets files stored in js runtime. It relates to files, which were loaded or created using Peachpie.Blazor API.
/// </summary>
public FormFile[] GetFiles() => _moduleRef.Invoke<FormFile[]>(_getfilesCommand);
/// <summary>
/// Gets post data of form.
/// </summary>
public Dictionary<string, string> GetPostData() => _moduleRef.Invoke<Dictionary<string, string>>(_getPostDataCommand);
/// <summary>
/// Reads a file content.
/// </summary>
public async Task<string> ReadFileContentAsBase64(int id) => await _moduleRef.InvokeAsync<string>(_readAsBase64Command, id);
/// <summary>
/// Creates an URL object from file by given id.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string CreateUrlObject(int id) => _moduleRef.Invoke<string>(_createUrlObjectCommand, id);
/// <summary>
/// Donwloads a file by given id.
/// </summary>
public void DownloadFile(int id) => _moduleRef.InvokeVoid(_downloadFileCommand, id);
/// <summary>
/// Creates a file with given name, data, and content type.
/// </summary>
public BrowserFile CreateFile(string data, string name, string contentType) => _moduleRef.Invoke<BrowserFile>(_createFileCommand, data, name, contentType);
#endregion

Просмотреть файл

@ -9,6 +9,9 @@ using System.Threading.Tasks;
namespace Peachpie.Blazor
{
/// <summary>
/// Basic implementaion of <see cref="IPHPService"/>.
/// </summary>
public class PHPService : IPHPService
{
private readonly IJSRuntime _jsRuntime;