xepozz/matcher
Composer 安装命令:
composer require xepozz/matcher
包简介
README 文档
README
A way to match values against a pattern.
Installation
composer require xepozz/matcher
Usage
Basic concept
A matcher is an object that is filled with a value and callbacks that will be called if the value matches the pattern.
Basic example
use Xepozz\Matcher\StringMatcher; /** * Each with* method returns a new instance of the matcher with the added condition. * So that means that the original matcher is not changed and you must use the returned instance. */ $matcher = (new StringMatcher('foo')) // or StringMatcher::of('foo') ->withLengthGreaterThan(2) ->withLengthLessThan(10) ->withContains('fo') ->withEndsWith('oo') ->withStartsWith('fo') ->with(function (string $value) { return $value === 'foo'; // callback for any custom checks }); $matcher->matches(); // true
Combining matchers
use Xepozz\Matcher\LogicMatcher;use Xepozz\Matcher\StringMatcher; $logicMatcher = new LogicMatcher(); $stringMatcher = new StringMatcher('bar'); $stringMatcher->matches(); // true $logicMatcher->not($stringMatcher) ->matches(); // false $stringMatcher->matches(); // true $logicMatcher->or($logicMatcher->not($stringMatcher), $stringMatcher) ->matches(); // true $logicMatcher->or($logicMatcher->not($stringMatcher), $logicMatcher->not($stringMatcher)) ->matches(); // false $logicMatcher->and($stringMatcher, $logicMatcher->not($stringMatcher)) ->matches(); // false
Existing Matchers
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-11-10