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;

$source = <<<'JSON'
{
  ":if": {
    "@": {
      "test": {
        ":logic:gte": [
          { ":logic:var": "order.total" },
          { ":type:int": 100 }
        ]
      }
    },
    "#": [{ "p": "Free shipping" }],
    ":else": [{ "p": "Shipping calculated at checkout" }]
  }
}
JSON;

$core = AbstractCore::default();
$tree = $core->parseJson($source);

echo $core->renderHtml($tree, [
    'order' => ['total' => 125],
]);

$tree = $core->parseJson($source);

// Editable Abstract source. Commands are preserved.
$jsonSource = $core->sourceJson($tree);
$amlSource = $core->sourceAml($tree);

// Canonical kind/name/type/op tree for inspection or interchange.
$canonical = $core->treeJson($tree);

// Evaluated canonical tree, before target mapping.
$resolved = $core->resolve($tree, ['order' => ['total' => 125]]);

// Final resolve -> map -> emit path.
$html = $core->renderHtml($tree, ['order' => ['total' => 125]]);

use Abstract\Parser\Markup\MarkupParseOptions;

$tree = $core->parseHtml(
    '<section><h1>Hello</h1></section>',
    options: new MarkupParseOptions(

$logic = $core->parseJson('{":==":[true,1]}');

echo $core->sourceJson($logic, pretty: false);
// {":logic:eq":[true,1]}

echo $core->sourceAml($logic, pretty: false);
// <:logic:eq><:type:bool>true</:type:bool><:type:int>1</:type:int></:logic:eq>

echo $core->sourceJson($logic, pretty: false, operatorStyle: 'symbol');
// {":==":[true,1]}

echo $core->sourceJson($logic, explicitTypedValues: true);

echo $core->treeJson($logic, pretty: true);

$diagnostics = [];
$tree = $core->parseJson(
    '{":logic:xor":[true,false]}',
    strict: false,
    diagnostics: $diagnostics,
);

$resolved = $core->resolve($tree, strict: false);



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(),
    ),
);
bash
composer test
php benchmarks/core-benchmark.php
php benchmarks/markup-benchmark.php