vantoozz/strings
Composer 安装命令:
composer require vantoozz/strings
包简介
OOP Strings Library
README 文档
README
True OOP library for strings manipulation
The goal of the library is providing an OOP way for strings manipulations.
It works with any object implementing Stringable interface. https://wiki.php.net/rfc/stringable.
Setup
Just run
composer require vantoozz/strings
Transformations
<?php declare(strict_types=1); use Vantoozz\Strings\Transforms\Acronym; use Vantoozz\Strings\Transforms\CaseToggled; use Vantoozz\Strings\Transforms\Reversed; use Vantoozz\Strings\Transforms\SnakeCased; use function Vantoozz\Strings\str; require_once __DIR__ . '/vendor/autoload.php'; $string = str('PHP: Hypertext Preprocessor'); echo new Acronym($string) . PHP_EOL; echo new CaseToggled($string) . PHP_EOL; echo new Reversed($string) . PHP_EOL; echo new SnakeCased($string) . PHP_EOL;
Will output
PHP php: hYPERTEXT pREPROCESSOR rossecorperP txetrepyH :PHP p_h_p:_hypertext_preprocessor
Available transformations
- Acronym
- CamelCased
- CaseToggled
- KebabCased
- LowerCased
- PascalCased
- Reversed
- SentenceCased
- SnakeCased
- TitleCased
- UpperCased
Joins
<?php declare(strict_types=1); use Vantoozz\Strings\Joins\EndingWith; use Vantoozz\Strings\Joins\Joined; use Vantoozz\Strings\Joins\StartingWith; use function Vantoozz\Strings\str; require_once __DIR__ . '/vendor/autoload.php'; $one = str('aabbc'); $two = str('ccddaa'); echo new Joined($one, $two) . PHP_EOL; echo new EndingWith($one, $two) . PHP_EOL; echo new StartingWith($one, $two) . PHP_EOL;
Will output
aabbcccddaa aabbccddaa ccddaabbc
Available joins
- Joined
- StartingWith
- EndingWith
Formats
<?php declare(strict_types=1); use Vantoozz\Strings\Exceptions\InvalidFormatException; use Vantoozz\Strings\Formats\Email; use function Vantoozz\Strings\str; require_once __DIR__ . '/vendor/autoload.php'; try { echo new Email(str('user@example.com')) . PHP_EOL; } catch (InvalidFormatException $e) { echo $e->getMessage() . PHP_EOL; } try { echo new Email(str('user%example.com')) . PHP_EOL; } catch (InvalidFormatException $e) { echo $e->getMessage() . PHP_EOL; }
Will output
user@example.com Invalid format
Available formats
- Hostname
- Ipv4
- Ipv6
- Mac
- Sha1
- Sha256
- Url
Composition
<?php declare(strict_types=1); use Vantoozz\Strings\Formats\Email; use Vantoozz\Strings\Joins\EndingWith; use Vantoozz\Strings\Transforms\CaseToggled; use function Vantoozz\Strings\str; require_once __DIR__ . '/vendor/autoload.php'; $username = str('User@'); $domain = str('@Example.Com'); echo new CaseToggled(new Email(new EndingWith($username, $domain))) . PHP_EOL;
Will output
uSER@eXAMPLE.cOM
Testing
./vendor/bin/phpunit
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-08