PHP code example of abstract / core

1. Go to this page and download the library: Download abstract/core 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/ */

    

abstract / core example snippets




bstract\AbstractCore;

$core = new AbstractCore();

$tree = $core->parseJson('{
  "div": {
    "@": {
      "class": "card"
    },
    "#": [
      { "h1": "Title" },
      { "p": "Body" }
    ]
  }
}');

echo $core->renderHtml($tree);
// <div class="card"><h1>Title</h1><p>Body</p></div>

use Abstract\AbstractCore;
use Abstract\Emitter\JsonEmitter;
use Abstract\Parser\Markup\MarkupParseOptions;

$core = new AbstractCore();
$tree = $core->parseHtmlFile('benchmarks/big-html.html', new MarkupParseOptions(

$tree = $core->parseHtml('Hello Test');

echo $core->treeJson($tree, pretty: false, mode: JsonEmitter::MODE_COMPACT);
// "Hello Test"

echo $core->renderHtml($tree);
// Hello Test

$tree = $core->parseYamlFile('page.abstract.yaml');

echo $core->renderHtml($tree);
echo $core->renderYaml($tree);

use Abstract\AbstractCore;
use Abstract\Emitter\JsxEmitter;
use Abstract\Mapper\ReactComponent;
use Abstract\Mapper\ReactMapper;
use Abstract\Render\RenderTarget;

$core = AbstractCore::default()
    ->withRenderTarget('jsx', RenderTarget::make(
        ReactMapper::make()
            ->component('input', ReactComponent::imported(
                source: '@headlessui/react',
                export: 'Input',
                as: 'HeadlessInput',
            )),
        new JsxEmitter(),
    ));

echo $core->renderJsx($tree);

use Abstract\AbstractCore;
use Abstract\Emitter\HtmlEmitter;
use Abstract\Mapper\HtmlElementMapping;
use Abstract\Mapper\HtmlMapper;
use Abstract\Render\RenderTarget;

$core = AbstractCore::default()
    ->withRenderTarget('html', RenderTarget::make(
        HtmlMapper::make()
            ->element('input', HtmlElementMapping::tag('x-input')),
        new HtmlEmitter(),
    ));

echo $core->renderHtml($tree);

$core = AbstractCore::fromConfig([
    'targets' => [
        'jsx' => [
            'components' => [
                'input' => [
                    'source' => '@headlessui/react',
                    'export' => 'Input',
                    'as' => 'HeadlessInput',
                ],
            ],
        ],
        'html' => [
            'elements' => [
                'input' => ['tag' => 'x-input'],
            ],
        ],
    ],
]);
bash
php benchmarks/core-benchmark.php
php benchmarks/markup-benchmark.php