定制 kuaukutsu/ds-collection 二次开发

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

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

kuaukutsu/ds-collection

Composer 安装命令:

composer require kuaukutsu/ds-collection

包简介

Is the abstract layer which covers functionality the data structure Collection.

README 文档

README

Коллекция объектов.

PHP Version Require Latest Stable Version License Psalm Level Psalm Type Coverage

Tech Stack

kuaukutsu/ds-collection is built on the following main stack:

Примеры

$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));

$collectionOther = new DtoCollection();
$collectionOther->attach(new Dto(3, 'third'));
$collectionOther->attach(new Dto(4, 'fourth'));

$collection->merge($collectionOther);

Фильтрация

$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));
$collection->attach(new Dto(3, 'first'));
$collection->attach(new Dto(4, 'second'));

$collectionByFiltered = $collection->filter(
    static fn(Dto $dto): bool => $dto->name === 'first'
);

Сортировка

$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));
$collection->attach(new Dto(3, 'first'));
$collection->attach(new Dto(4, 'second'));

$sortCollection = $collection->sort(
    static fn(Dto $a, Dto $b): int => strcmp($a->name, $b->name)
);

Индексация

В классе коллекции необходимо указать на основании какого свойства объекта индексировать коллекцию. Это делается при помощи метода indexBy, например:

/**
 * @param Dto $item
 * @return int
 */
protected function indexBy($item): int
{
    return $item->id;
}
/**
 * @param Dto $item
 * @return string
 */
protected function indexBy($item): string
{
    return $item->name;
}

Это позволяет получить быстрый доступ к объекту по ключу индекса, например для indexBy по ключу name:

$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));

$dto = $collection->get('second');

Составные ключи

Ключ индексирования может быть составным, например:

/**
 * @param Dto $item
 * @return array<scalar>
 */
protected function indexBy($item): array
{
    return [$item->id, $item->name];
}
$collection = new DtoCollection();
$collection->attach(new Dto(1, 'first'));
$collection->attach(new Dto(2, 'second'));
$collection->attach(new Dto(22, 'second'));

$dto = $collection->get(2, 'second');

Testing

Unit testing

The package is tested with PHPUnit. To run tests:

make phpunit
PHP_VERSION=8.1 make phpunit

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

make psalm
PHP_VERSION=8.1 make psalm
make phpstan
PHP_VERSION=8.4 make phpstan

Code Sniffer

make phpcs

Rector

make rector

kuaukutsu/ds-collection 适用场景与选型建议

kuaukutsu/ds-collection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43.09k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 kuaukutsu/ds-collection 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-21