承接 angelopereyra/replace 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

angelopereyra/replace

Composer 安装命令:

composer require angelopereyra/replace

包简介

Replace substring using custom identifiers

README 文档

README

Build Status

Installation

> composer require angelopereyra/replace

Usage

use Replace\Replaceable;

...

$url = new Replaceable('https://mysite.{domain}.com');

From the above example, we can set the value for {domain} substring in two ways:

$url->addLookup('domain', 'local');

// dumping a dictionary
$url->setLookup([
    'domain' => 'local'
]);

Then cast the object to string to get the result

echo (string)$url; // prints "https://mysite.local.com"

Modify the token format

Pass a string as a second argument to the constructor to customize what your token would look like:

$url = new Replaceable('https://mysite.$$domain.com', '$$++key++');
// ++key++ is the 🔑

In some cases you might just need to pass a callable:

$url = new Replaceable('https://mysite.UwU domain UwU.com', function($key) {
    return 'UwU ' . $key . ' UwU';
});

A static helper is also exposed for convenience

$lookup = [
    'type'   => 'Bearer',
    'token'  => 'xoxb-83029aurioDnd'
];

Replaceable::parse('Authorization: @type @token', $lookup, '@++key++')
// prints "Authorization: Bearer xoxb-83029aurioDnd"

Identify tokens

Suppose you have the subject string below:

Hello, {name}. You look {adjective} today. 

Replaceable can identify the tokens according to the given token format. In this case, we will be using the default format which is {++key++}.

We can identify the tokens using the following usage:

$subject = file_get_contents('...');

$sentence = new Replaceable($subject);

$sentence->identifyTokens(false);
// returns ['name', 'adjective']

To identify tokens with respect to word boundary, set the 1st parameter to true:

$sentence->identifyTokens(true);
// returns ['adjective']

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固