This lib parse some template or stub. You can use it as a PHP terminal command or in your code.
Kudos to Mustache!
To use as a CLI command, you can download the phar file:
Important: remember to replace the
version-number
!
Install via composer:
composer require kanata-php/mustachio
This can serve as a file stub parser or a very simple template engine. By default, it uses mustache to parse the input file.
use Mustachio\Service as Stache;
$parsedContent = Stache::parse('my content with {{PLACEHOLDER}}', ['PLACEHOLDER' => 'value']);
// output: my content with value
This can be used to replace/remove lines in files.
use Mustachio\Service as Stache;
Stache::replaceFileLineByCondition(
file: '/path/to/file',
conditions: [
fn($l) => strpos($l, 'identifier-1') !== false,
fn($l) => strpos($l, 'identifier-2') !== false,
],
values: [
'replacement-for-identifier-1',
'replacement-for-identifier-2',
],
toRemove: function ($l) {
return strpos($l, 'identifier-to-remove') !== false;
},
);
// output: update the original file
This can process input files giving back the output file parsed with the given placeholders.
php bin/stache "/path/to/my.stub" "/path/to/my.php" "PLACEHOLDER:value;PLACEHOLDER2:value2"
vendor/bin/pest