kanata-php/mustachio

There is no license information available for the latest version (0.0.2) of this package.

Stubs processor.

Fund package maintenance!
kanata-php

0.0.2 2022-11-21 04:32 UTC

This package is auto-updated.

Last update: 2024-04-21 07:27:28 UTC


README

mustachio.svg

Tests 68747470733a2f2f636f6465636f762e696f2f67682f6b616e6174612d7068702f6d757374616368696f2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d5439304759465257505a

Mustachio

This lib parse some template or stub. You can use it as a PHP terminal command or in your code.

Kudos to Mustache!

Install

CLI

To use as a CLI command, you can download the phar file:

Important: remember to replace the version-number!

Library

Install via composer:

composer require kanata-php/mustachio

Usage

App Service

Stub Parser

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

Line Replacement

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

Cli Phar Usage

Stub Parser

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"

Tests

vendor/bin/pest