infocyph/arraykit 问题修复 & 功能扩展

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

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

infocyph/arraykit

最新稳定版本:2.03.2

Composer 安装命令:

composer require infocyph/arraykit

包简介

A Collection of useful PHP array functions.

README 文档

README

Security & Standards Codacy Badge Packagist Downloads License: MIT Packagist Version Packagist PHP Version GitHub Code Size

ArrayKit is a modern PHP 8.2+ library for elegant, high-performance array manipulation, dot notation utilities, dynamic configuration, hookable collections, and more. From shallow single arrays to deeply nested data structures — ArrayKit provides a fluent, reliable toolkit for real-world PHP projects.

???? Features at a Glance

Single-Dimensional HelpersMulti-Dimensional HelpersDot Notation Get/Set/FlattenDynamic Config with HooksCollection & Hooked CollectionTraits for DTO & HookingPipeline for Collection OpsGlobal Helpers (functions.php)

???? Modules

➤ Array Helpers

Helper Description
ArraySingle Helpers for single-dimensional arrays (detect list/assoc, filter, paginate, duplicates, averages).
ArrayMulti Helpers for multi-dimensional arrays (flatten, collapse, depth, recursive sort, filter).
DotNotation Get/set/remove values using dot keys; flatten & expand nested arrays with dot keys.
BaseArrayHelper Internal shared base for consistent API across helpers.

➤ Config System

Class Description
Config Immutable dot-access configuration loader.
DynamicConfig Extends Config with on-get/on-set hooks to transform values dynamically (e.g., encrypt/decrypt, auto-format).
BaseConfigTrait Shared config logic.

➤ Collections

Class Description
Collection OOP array wrapper implementing ArrayAccess, Iterator, Countable, JsonSerializable.
HookedCollection Extends Collection with on-get/on-set hooks for real-time transformation of values.
Pipeline Functional-style pipeline for chaining operations on collections.
BaseCollectionTrait Shared collection behavior.

➤ Traits

Trait Description
HookTrait Generic hook system for on-get/on-set callbacks. Used by DynamicConfig & HookedCollection.
DTOTrait Utility trait for DTO-like behavior: populate, extract, cast arrays/objects easily.

➤ Global Helpers

File Description
functions.php Global shortcut functions for frequent array/config tasks.

✅ Requirements

  • PHP 8.2 or higher

⚡ Installation

composer require infocyph/arraykit

???? Quick Examples

???? Single-Dimensional Helpers

use Infocyph\ArrayKit\Array\ArraySingle; $list = [1, 2, 3, 2]; // Is it a list? $isList = ArraySingle::isList($list); // true // Duplicates $dupes = ArraySingle::duplicates($list); // [2] // Pagination $page = ArraySingle::paginate($list, page:1, perPage:2); // [1, 2]

???? Multi-Dimensional Helpers

use Infocyph\ArrayKit\Array\ArrayMulti; $data = [ [1, 2], [3, [4, 5]] ]; // Flatten to one level $flat = ArrayMulti::flatten($data); // [1, 2, 3, 4, 5] // Collapse one level $collapsed = ArrayMulti::collapse($data); // [1, 2, 3, [4, 5]] // Nesting depth $depth = ArrayMulti::depth($data); // 3 // Recursive sort $sorted = ArrayMulti::sortRecursive($data);

???? Dot Notation

use Infocyph\ArrayKit\Array\DotNotation; $user = [ 'profile' => ['name' => 'Alice'] ]; // Get value $name = DotNotation::get($user, 'profile.name'); // Alice // Set value DotNotation::set($user, 'profile.email', 'alice@example.com'); // Flatten $flat = DotNotation::flatten($user); // [ 'profile.name' => 'Alice', 'profile.email' => 'alice@example.com' ]

???? Dynamic Config with Hooks

use Infocyph\ArrayKit\Config\DynamicConfig; $config = new DynamicConfig(); // Load from file $config->loadFile(__DIR__.'/config.php'); // Hook: auto-hash password when set $config->onSet('auth.password', fn($v) => password_hash($v, PASSWORD_BCRYPT)); // Hook: decrypt when getting 'secure.key' $config->onGet('secure.key', fn($v) => decrypt($v)); // Use it $config->set('auth.password', 'secret123'); $hashed = $config->get('auth.password');

???? Hooked Collection

use Infocyph\ArrayKit\Collection\HookedCollection; $collection = new HookedCollection(['name' => 'alice']); // Hook on-get: uppercase $collection->onGet('name', fn($v) => strtoupper($v)); // Hook on-set: prefix $collection->onSet('role', fn($v) => "Role: $v"); echo $collection['name']; // ALICE $collection['role'] = 'admin'; echo $collection['role']; // Role: admin

???? DTO Trait Example

use Infocyph\ArrayKit\traits\DTOTrait; class UserDTO { use DTOTrait; public string $name; public string $email; } $user = new UserDTO(); $user->fromArray(['name' => 'Alice', 'email' => 'alice@example.com']); $array = $user->toArray();

???? Support

Have a bug or feature idea? Please open an issue.

???? License

Licensed under the MIT License — use it freely for personal or commercial projects. See LICENSE for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固