xepozz/matcher 问题修复 & 功能扩展

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

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

xepozz/matcher

Composer 安装命令:

composer require xepozz/matcher

包简介

README 文档

README

A way to match values against a pattern.

Latest Stable Version Total Downloads phpunit codecov

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-11-10