Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 667 Bytes

README.md

File metadata and controls

34 lines (22 loc) · 667 Bytes

Farser

An experiment in template parsing (in PHP) that's pretty simple minded and tries to implement nested scopes in a non-scary way.

And... look ma, no regex!

Turns

{$A fiz="baz" dir="ls"}foo{dir}{$B dir="dir"}bar{fiz}{dir}{/$B}{/$A}

into

foolsbarbazdir

also handles a simple callback mechanism

$farser = new Farser();
$farser->setRaw('{$A}{foo}{$B}{foo}{dir}{/$B}{/$A}');

$farser->addCallback('A', function (& $scope)
{
    $scope['vars']['foo'] = 'baz';
});

$farser->addCallback('B', function (& $scope)
{
    $scope['vars']['dir'] = 'ls';
});

echo $farser->parse();

// output: bazbazls