Skip to content

enhance-dev/enhance-ssr-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Enhance SSR PHP

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.

About

Enhance SSR for PHP

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages