mf/stringify
最新稳定版本:7.0.0
Composer 安装命令:
composer require mf/stringify
包简介
Simple and tiny class (function) to stringify anything in PHP.
README 文档
README
Simple and tiny class (function) to stringify anything in PHP.
Installation
composer require mf/stringify
Usage
By class and static method
use MF\Stringify\Stringify; echo Stringify::stringify([1, 2, 3]); // "[1, 2, 3]"
By standalone function
use function MF\Stringify\stringify; echo stringify([1, 2, 3]); // "[1, 2, 3]"
$result = array_map(stringify(...), [1, 'two']); // ['1', '"two"']
Sprintf bonus
with a new
%Aplaceholder forstringifyfunction
use function MF\Stringify\sprintf; echo sprintf('Hello %A!', 'world'); // Hello "world"! echo sprintf('Hello %A!', ['world']); // Hello ["world"]!
Example
NOTE: values longer than 100 chars is shrinked to 100 chars with ... suffix
For easier examples, let's use a standalone function
| Type | PHP | Result (string) |
|---|---|---|
| NULL | stringify(null); |
null |
| bool | stringify(true); |
true |
| bool | stringify(false); |
false |
| string | stringify(''); |
"" |
| string | stringify('Some string'); |
"Some string" |
| int | stringify(42); |
42 |
| float | stringify(3.14); |
3.14 |
| array | stringify([1, 2, 3]); |
[1, 2, 3] |
| array | stringify(['foo' => 'bar']); |
["foo" => "bar"] |
| array | stringify(['person' => ['name' => 'Peter Parker'], 'alterego' => 'spider-man']); |
["person" => ["name" => "Peter Parker"], "alterego" => "spider-man"] |
| object | stringify(new \Foo\Bar()); |
Foo\Bar |
| object | stringify(new \DateTime()); |
DateTime { 2018-11-15T10:20:30+00:00 } |
| object | stringify(Seq::range('1..4')); |
MF\Collection\Immutable\Seq [1, 2, 3, 4] |
Changelog
For latest changes see CHANGELOG.md file. We follow Semantic Versioning.
Contributing and development
Install dependencies
composer install
Run tests
For each pull-request, unit tests as well as static analysis and codestyle checks must pass.
To run all those checks execute:
composer all
统计信息
- 总下载量: 11.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-14