PHP code example of automattic / blocks-engine-php-transformer
1. Go to this page and download the library: Download automattic/blocks-engine-php-transformer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
automattic / blocks-engine-php-transformer example snippets
use Automattic\BlocksEngine\PhpTransformer\ArtifactCompiler\ArtifactCompiler;
use Automattic\BlocksEngine\PhpTransformer\FormatBridge\FormatBridge;
use Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\HtmlTransformer;
use Automattic\BlocksEngine\PhpTransformer\WordPressSitePlan\WordPressSitePlanView;
$htmlResult = (new HtmlTransformer())->transform('<h1>Hello</h1>', array(
'source' => 'fixture:home-html',
'scope' => 'import-preview',
))->toArray();
$formatResult = (new FormatBridge())->convertResult('# Hello', 'markdown', 'blocks', array(
'context' => array(
'strict' => true,
'allow_fallbacks' => false,
),
))->toArray();
$artifactResult = (new ArtifactCompiler())->compile(array(
'generated_html' => '<main><h1>Hello</h1></main>',
))->toArray();
$plan = (new WordPressSitePlan())->fromResult($artifactResult);
$planView = (new WordPressSitePlanView())->fromResult($artifactResult);
$resolvedPlan = (new WordPressSitePlanResolver())->resolve($plan, array(
'theme_uri' => 'https://example.test/wp-content/themes/generated-site',
));
$result = blocks_engine_php_transformer_transform_html('<h1>Hello</h1>', array(
'source' => 'plugin:consumer',
'scope' => 'import-preview',
));
$artifact = blocks_engine_php_transformer_compile_artifact(array(
'generated_html' => '<main><h1>Hello</h1></main>',
));
$result = (new FormatBridge())->convertResult($html, 'html', 'blocks')->toArray();
if ('failed' === $result['status']) {
$diagnosticCode = $result['diagnostics'][0]['code'] ?? '';
}
sh
homeboy release php-transformer --dry-run --skip-publish --no-github-release
sh
homeboy release php-transformer --path /path/to/blocks-engine/php-transformer --dry-run --skip-publish --no-github-release
sh
homeboy release php-transformer --skip-publish --no-github-release