enhance-dev/ssr 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

enhance-dev/ssr

最新稳定版本:v0.0.5

Composer 安装命令:

composer require enhance-dev/ssr

包简介

A PHP library for server-side rendering with Enhance

README 文档

README

A library for server rendering web components in PHP that is compatible with Enhance SSR (Enhance.dev).

Runtime: WASM or native PHP

This package includes both a WASM and native PHP version of enhance ssr. The WASM version allows component definitions written in JavaScript, but has specific requirements for the hosting environment that may be challenging. The examples directory includes examples of both versions.

Install

This package can be managed and installed with Composer:

composer require enhance-dev/ssr

The Extism dependency currently requires "minimum-stability":"dev" in the composer.json file.

Run Examples

To run the native and WASM examples run composer serve-native or composer serve-wasm respectively.

Usage:

See usage examples for native PHP and WASM in the examples directory.

Native PHP

<?php
require "../../../vendor/autoload.php";

use Enhance\Enhancer;
use Enhance\Elements;
use Enhance\ShadyStyles;

$elementPath = __DIR__ . "/../resources";
$elements = new Elements($elementPath);
$scopeMyStyle = new ShadyStyles();
$enhance = new Enhancer([
    "elements" => $elements,
    "initialState" => [],
    "styleTransforms" => [[$scopeMyStyle, "styleTransform"]],
    "enhancedAttr" => true,
    "bodyContent" => false,
]);

$htmlString = <<<HTMLDOC
<!DOCTYPE html>
       <html>
       <head>
       </head>
       <body>
           <my-header><h1>Hello World</h1></my-header>
       </body>
       </html>
HTMLDOC;

$output = $enhance->ssr($htmlString);

echo $output;

WASM

<?php
require "../../../vendor/autoload.php";

use Enhance\EnhanceWASM;
use Enhance\Elements;

$elementPath = "../resources";
$elements = new Elements($elementPath, ["wasm" => true]);
$enhance = new EnhanceWASM(["elements" => $elements->wasmElements]);

$input = [
    "markup" => "<my-header>Hello World</my-header>",
    "initialState" => [],
];

$output = $enhance->ssr($input);

$htmlDocument = $output->document;

echo $htmlDocument . "\n";

Install Extism Runtime Dependency (for WASM only)

For the WASM version there are additional requirements. For this library, you first need to install the Extism Runtime by following the instructions in the PHP SDK Repository.

Acknowledgements

Thank you @mariohamann for prototyping a PHP example in using Extism https://github.com/mariohamann/enhance-ssr-wasm/tree/experiment/extism.

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-04-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固