kanata-php/mustachio

该包最新版本(0.0.2)的许可证信息不可用。

占位符处理器。

资助包维护!
kanata-php

0.0.2 2022-11-21 04:32 UTC

This package is auto-updated.

Last update: 2024-09-21 08:20:02 UTC


README

Tests

Mustachio

这个库解析一些模板或占位符。您可以使用它作为PHP 命令行命令或在您的 代码 中。

感谢 Mustache

安装

CLI

要作为CLI命令使用,您可以下载phar文件

重要:记得替换 版本号

通过composer安装

composer require kanata-php/mustachio

用法

应用服务

占位符解析器

这可以作为文件占位符解析器或一个非常简单的模板引擎。默认情况下,它使用 mustache 来解析输入文件。

use Mustachio\Service as Stache;
$parsedContent = Stache::parse('my content with {{PLACEHOLDER}}', ['PLACEHOLDER' => 'value']);
// output: my content with value

行替换

这可以用于替换/删除文件中的行。

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 使用

占位符解析器

这可以处理输入文件,返回用给定占位符解析的输出文件。

php bin/stache "/path/to/my.stub" "/path/to/my.php" "PLACEHOLDER:value;PLACEHOLDER2:value2"

测试

vendor/bin/pest