定制 singlequote/laravel-text-parser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

singlequote/laravel-text-parser

最新稳定版本:2.0.0

Composer 安装命令:

composer require singlequote/laravel-text-parser

包简介

A package to replace words in a text with values from a array. Also supports aliases and excluded properties

README 文档

README

Latest Version on Packagist Total Downloads

A package to replace words in a text with values from a array. Also supports aliases and excluded properties.

Installation

You can install the package via composer:

composer require singlequote/laravel-text-parser

Basic Usage

Parser::text('Hello [who]')->values(['who' => 'world'])->parse(); // Hello world

Parser::text('Hello {who}')->values(['who' => 'world'])->tags(['{', '}'])->parse(); // Hello world

Parser::text('Hello [who]')->values(['who' => 'world'])->exclude(['who'])->parse(); // Hello [who]

Parser::text('Hello [what]')->values(['who' => 'world'])->aliases(['what' => 'who'])->parse(); // Hello world

Using arrays as values

$values = [
    'user' => [
        'name' => [
            'first_name' => 'Foo',
            'last_name' => 'Bar'
        ],
        'email' => 'example@example.com'
    ]
];

$input = "[user.name.first_name][user.name.last_name] - [user.email]";

$result = Parser::text($input)->values($values)->parse();

will generate FooBar - example@example.com

Available methods

All methods can be chained together like text()->values()->aliases() and can be in any order. But you always have to start with the text() function.

text

This sets the string you want to parse

    $parser = Parser::text('string')

values

This sets the values to use while parsing. Must be a array

    $parser->values([]);

tags

Tags are the characters around the keys you want to parse. Default [ and ]

    $parser->tags(['{','}']);

exclude

Sets the keys which are excluded from parsing

    $parser->exclude(['key', 'key2']);

aliases

Sets the aliases. Aliases can be used to map a value to a different name. So for example you can set the aliases to ['name' => 'username'] to map username to name

    $parser->exclude(['alias', 'value key']);

parse

Parses the text and returns the parsed string

    $parser->exclude(['alias', 'value key']);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email info@quotec.nl instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 196
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固