simklee/string-buffer
最新稳定版本:1.0.8
Composer 安装命令:
composer require simklee/string-buffer
包简介
A string buffer to manipulate strings object orientated with fluent interface and method chaining.
README 文档
README
A small library to manipulate strings object orientated with fluent interface and method chaining.
Installation
composer require simklee/string-buffer
Usage
use Simklee\LaravelStringBuffer\StringBuffer;
// Sample with append methods
$buffer = new StringBuffer();
$buffer->append('some string')
->appendIf($condition, 'true', 'false')
->appendIfNot($condition, 'false', 'true')
->appendFormatted('%s, %s', 'LastName', 'FirstName')
->appendIfNull($isNull, 'is null', 'is NOT null')
->appendIfNotNull($isNotNull, 'is NOT null', 'is null')
->appendImplode(['a', 'b', 'c'], ',');
echo $buffer->toString();
// Sample with prepend methods
echo StringBuffer::create('some string')
->prepend('some string')
->prependIf($condition, 'true', 'false')
->prependIfNot($condition, 'false', 'true')
->prependFormatted('%s, %s', 'LastName', 'FirstName')
->prependIfNull($isNull, 'is null', 'is NOT null')
->prependIfNotNull($isNotNull, 'is NOT null', 'is null')
->prependImplode(['a', 'b', 'c'], ',')
->toString();
Methods
| Method | Description |
|---|---|
| __construct(string $string = null) | Constructor of StringBuffer |
| StringBuffer static create(string $string = null) | Creates an instance of StringBuffer. Good for method chaining |
| string toString() | Get the string value of StringBuffer |
| string __toString() | Get the string value of StringBuffer |
| StringBuffer append(string $string) | Appends a string to the buffer. |
| StringBuffer appendFormatted(string $format, string ...$values) | Appends a formatted string (with sprintf()) to the buffer. |
| StringBuffer appendIf(bool $condition, string $string, string $else = null) | Appends a string to the buffer if $condition is true, otherwise $else (if not null) |
| StringBuffer appendIfNot(bool $condition, string $string, string $else = null) | Appends a string to the buffer if $condition is false, otherwise $else (if not null) |
| StringBuffer appendIfNull(mixed $value, string $string, string $else = null) | Appends a string to the buffer if $value is null, otherwise $else (if not null) |
| StringBuffer appendIfNotNull(mixed $value, string $string, string $else = null) | Appends a string to the buffer if $value is NOT null, otherwise $else (if not null) |
| StringBuffer appendImplode(array $values, string $separator = ' ') | Appends an imploded array to the buffer. |
| StringBuffer prepend(string $string) | Prepends a string to the buffer. |
| StringBuffer prependFormatted(string $format, string ...$values) | Prepends a formatted string (with sprintf()) to the buffer. |
| StringBuffer prependIf(bool $condition, string $string, string $else = null) | Prepends a string to the buffer if $condition is true, otherwise $else (if not null) |
| StringBuffer prependIfNot(bool $condition, string $string, string $else = null) | Prepends a string to the buffer if $condition is false, otherwise $else (if not null) |
| StringBuffer prependIfNull(mixed $value, string $string, string $else = null) | Prepends a string to the buffer if $value is null, otherwise $else (if not null) |
| StringBuffer prependIfNotNull(mixed $value, string $string, string $else = null) | Prepends a string to the buffer if $value is NOT null, otherwise $else (if not null) |
| StringBuffer prependImplode(array $values, string $separator = ' ') | Prepends an imploded array to the buffer. |
统计信息
- 总下载量: 1.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-19