定制 benjaminmal/parity-checker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

benjaminmal/parity-checker

Composer 安装命令:

composer require benjaminmal/parity-checker

包简介

Parity checker

README 文档

README

Continuous integration

A PHP parity checker. Useful when you want to check if many objects are having the same datas. It has many options so you can configure the behavior you need, especially speaking of object recursion.

Installation

$ composer require benjaminmal/parity-checker

Getting started

Create the Parity checker using the factory:

$parityChecker = ParityChecker::create();

Or using your implementations using Symfony PropertyAccess & PropertyInfo components

/** @var PropertyAccessorInterface $propertyAccessor */
/** @var PropertyInfoExtractorInterface $propertyInfoExtractor */

$parityChecker = new ParityChecker($propertyAccessor, $propertyInfoExtractor);

Check your objects

$errors = $parityChecker->checkParity([$object1, $object2]);
if (! $errors->hasErrors()) {
    // You're all set !
}

Usages

Options

$errors = $parityChecker->checkParity([$object1, $object2], [
    // Do not perform check on these types
    'ignore_types' => ['object', 'resource', \DateTimeInterface::class, '$objectProperty1'],
    
    // Perform check only on these types
    'only_types' => ['string', 'float'],

    // Perform a loose check ('==' instead of '===') on theses types
    'loose_types' => 'array',

    // Set the recursion limit for objects
    'deep_object_limit' => 0,
    
    // Set DateTime format to check
    'datetime_check_format' => false,
    
    // Set DateInterval format to check
    'date_interval_format' => '%R %Y %M %D %H %I %S %F',
    
    // Set DateTime zone mapping to name
    'datetime_zone' => true,
    
    // Set a data mapper closure
    'data_mapper' => [
        'my-mapper' => new ParityCheckerCallback(
            'array',
            fn ($value, string $property, array $options): mixed => $value['something'],
        ),
    ],
    
    // Custom checkers. You can set you own checker which replace other.
    'custom_checkers' => [
        'my-checker' => new ParityCheckerCallback(
            ['$property'],
            fn ($value1, $value2, string $property, array $options): bool => true,
        ),
    ],
]);
Option Description Accepted types Default values
ignore_types Do not perform check on these types string[]|string. Can be any types. Checked by the is_ functions, classes/interfaces names or object properties (must be prefixed by $) object
only_types Perform checks only on these types. ignore_types is evaluated before, so if you set the same type in both ignore_types and only_types, the type will be ignored. string[]|string. Can be any types. Checked by the is_ functions, classes/interfaces names or object properties (must be prefixed by $) none
loose_types On which type to perform loose check (==) instead of (===) string[]|string. Can be any types. Checked by the is_ functions, classes/interfaces names or object properties (must be prefixed by $) none
deep_object_limit The object recursion limit int 0
data_mapper Replace value before checking by your closure ParityCheckCallbackInterface[] datetime_check_format, date_interval_format, datetime_zone mappers
datetime_check_format The format that DateTime must be check with bool|string. Has to be a valid DateTime format. If it's true, Y-m-d H:i:s is used. true
date_interval_format The format that DateInterval must be check with bool|string. Has to be a valid DateInterval format. If it's true, %R %Y %M %D %H %I %S %F is used. true
datetime_zone Map DateTimeZone objects to its timezone name in order to check it. E.g Europe/Paris bool true
custom_checkers You can set you own checker which replace other ParityCheckCallbackInterface[] none

Errors

$errors = $parityChecker->checkParity([$object1, $object2], $options);

if ($errors->hasError()) {
    foreach ($errors as $error) {
        $property = $error->getProperty();
        $object1 = $error->getObject1();
        $object2 = $error->getObject2();

        $errorValue1 = $error->getObject1Value();
        $errorValue2 = $error->getObject2Value();
    }
}

benjaminmal/parity-checker 适用场景与选型建议

benjaminmal/parity-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 106 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 benjaminmal/parity-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 benjaminmal/parity-checker 我们能提供哪些服务?
定制开发 / 二次开发

基于 benjaminmal/parity-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 106
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-05