theroadbunch/string-bean 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

theroadbunch/string-bean

最新稳定版本:v0.1

Composer 安装命令:

composer require theroadbunch/string-bean

包简介

A collection of functions for formatting strings

README 文档

README

Using a variety of provided formatters, you can format strings and arrays of strings quickly and easily.

Build Status Scrutinizer Code Quality License: MIT

Installation

composer require theroadbunch/string-bean

Usage

Formatters

Format a single string

<?php

use \RoadBunch\StringBean\UpperCaseWordsFormatter;

$formatter = new UpperCaseWordsFormatter();

/* Format a string */
echo $formatter->format('these.are_some-words_to uppercase');

/* Format a list of strings */
print_r($formatter->formatList('this will be upper case', 'and.so.will.this'));

output:

These.Are_Some-Words_To Uppercase

Array 
(
    [0] => 'This Will Be Upper Case'
    [1] => 'And.So.Will.This'
)

Available Formatters

Formatter Ex: original Ex: formatted
SplitCamelCaseWordsFormatter::class splitCamelCase split Camel Case
UpperCaseWordsFormatter::class upper case_words formatter Upper Case_Words Formatter

SplitCamelCaseWordsFormatter can split CamelCase strings with acronyms and abbreviations.

Formatter Ex: original Ex: formatted
SplitCamelCaseWordsFormatter::class ThisWILLWork This WILL Work
SplitCamelCaseWordsFormatter::class evenT.H.I.S.Works even T.H.I.S. Works

Trimmers

<?php

use RoadBunch\StringBean\PrefixTrimmer;

$formatter = new PrefixTrimmer('This');

/* Trim a word off the front of a string */
echo $formatter->format('This is a string of words');

/* Trimmers are case-sensitive */
echo $formatter->format('this is a string of words');

output:

is a string of words

this is a string of words

Available Trimmers

Note: Trimmers implement the same interface as Formatters: FormatterInterface

Trimmer Trim Value Ex: original Ex: formatted
PrefixTrimmer pref_ pref_A String A String
SuffixTrimmer ula1 Formula1 Form

Use a combination of Formatters

<?php

use RoadBunch\StringBean\CombinationFormatter;
use RoadBunch\StringBean\SplitCamelCaseFormatter;
use RoadBunch\StringBean\UpperCaseWordsFormatter;
use RoadBunch\StringBean\AbstractFormatter;

$formatter = new CombinationFormatter(
    new SplitCamelCaseFormatter(),
    new UpperCaseWordsFormatter(),
    // feel free to create a formatter on the fly
    new class extends AbstractFormatter {
        public function format(string $subject) : string{
            return "~={$subject}=~";
        }
    }
);
echo $formatter->format('aStringToFormat');

print_r($formatter->formatList('aStringToFormat', 'wild'));

output:

~=A String To Format=~

Array
(
    [0] => ~=A String To Format=~
    [1] => ~=Wild=~
)

Create your own formatter

<?php

use RoadBunch\StringBean\AbstractFormatter;

class L33tSpeakFormatter extends AbstractFormatter
{
    public function format(string $subject): string
    {
        return str_ireplace(['T', 'E', 'A'], ['7', '3', '4'], strtoupper($subject));
    }
};

$formatter = new L33tSpeakFormatter();
echo $formatter->format('leet speak');

output:

L337 SP34K

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固