定制 joby/toolbox 二次开发

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

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

joby/toolbox

Composer 安装命令:

composer require joby/toolbox

包简介

A lightweight collection of useful general purpose PHP tools with no dependencies. Committed to always at least having minimal dependencies.

README 文档

README

A lightweight collection of useful general purpose PHP tools with no dependencies. Committed to always at least having minimal dependencies.

URL-safe Base64

Encoding has functions for URL-safe base64 encoding. Simple implementation that replaces + and / with - and _, respectively. Also strips right padding = signs as they are not necessary for decoding.

use Joby\Toolbox\Strings\Encoding;

// encode a string or binary data
$encoded = Encoding::base64url_encode($your_data);

// decode it
$decoded = Encoding::base64_url_decode($encoded);

Array Tools

The ArrayFunctions class provides enhanced array manipulation capabilities:

  • shift_n: Shifts multiple elements from the start of an array at once

    $array = [1, 2, 3, 4, 5];
    $shifted = ArrayFunctions::shift_n($array, 2); // Returns [1, 2]
    // $array is now [3, 4, 5]
  • pop_n: Pops multiple elements from the end of an array at once

    $array = [1, 2, 3, 4, 5];
    $popped = ArrayFunctions::pop_n($array, 2); // Returns [5, 4]
    // $array is now [1, 2, 3]
  • min/max: Enhanced versions of PHP's min/max functions with special handling for null values

    $array = [1, 2, 3, null, 5];
    $min = ArrayFunctions::min($array); // Returns null (nulls are low by default)
    $min = ArrayFunctions::min($array, true); // Returns 1 (nulls are high)
    $max = ArrayFunctions::max($array); // Returns 5 (nulls are low by default)
    $max = ArrayFunctions::max($array, true); // Returns null (nulls are high)

Sorting Tools

The sorting component provides flexible and powerful sorting capabilities:

Sort Class

Static interface for one-time sorting operations:

// Basic sorting
$data = [3, 1, 4, 1, 5, 9];
Sort::sort($data, fn ($a, $b) => $a <=> $b);

// Multi-criteria sorting (even numbers first, then by value)
$data = [3, 1, 4, 1, 5, 9];
Sort::sort($data, fn ($a, $b) => $a % 2 <=> $b % 2, fn ($a, $b) => $a <=> $b);

// Reverse sorting
Sort::sort($data, Sort::reverse(fn ($a, $b) => $a <=> $b));

// Sorting objects by method results
Sort::sort($objects, Sort::compareMethods('getNumber'));

// Sorting objects by property values
Sort::sort($objects, Sort::compareProperties('itemName'));

// Sorting arrays by key values
Sort::sort($arrayOfArrays, Sort::compareArrayValues('name'));

// Sorting by callback results (e.g., string length)
Sort::sort($strings, Sort::compareCallbackResults(strlen(...)));

Sorter Class

For reusable sorting operations:

// Create a sorter with multiple criteria
$sorter = new Sorter(
    fn ($a, $b) => $a->priority <=> $b->priority,
    fn ($a, $b) => $a->name <=> $b->name
);

// Sort multiple arrays with the same criteria
$sorter->sort($array1);
$sorter->sort($array2);

Sortable Interface

Objects can implement the Sortable interface to provide a default sorting value:

class MyClass implements Sortable {
    public function sortByValue(): string|int|float|bool {
        return $this->priority;
    }
}

Range Tools

The Ranges component provides tools for working with ranges of values:

AbstractRange

An abstract base class for implementing ranges with various value types:

  • Boolean operations: booleanAnd, booleanOr, booleanXor, booleanNot
  • Comparison methods: equals, intersects, contains, adjacent
  • Boundary management: setStart, setEnd, start, end
// Example using IntegerRange implementation
$range1 = new IntegerRange(1, 5);
$range2 = new IntegerRange(3, 8);

// Intersection (AND)
$intersection = $range1->booleanAnd($range2); // Range from 3 to 5

// Union (OR)
$union = $range1->booleanOr($range2); // Collection with range from 1 to 8

// Exclusive OR
$xor = $range1->booleanXor($range2); // Collection with ranges 1-3 and 5-8

RangeCollection

Manages collections of ranges with operations for merging and manipulation:

// Create a collection of ranges
$collection = RangeCollection::create($range1, $range2);

// Merge overlapping and adjacent ranges
$merged = $collection->mergeRanges();

IntegerRange

A concrete implementation of AbstractRange for integer values.

joby/toolbox 适用场景与选型建议

joby/toolbox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 joby/toolbox 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-28