定制 jojo1981/typed-set 二次开发

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

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

jojo1981/typed-set

Composer 安装命令:

composer require jojo1981/typed-set

包简介

Typed set

README 文档

README

PHP Status Coverage Status Latest Stable Version Total Downloads License

Author: Joost Nijhuis <jnijhuis81@gmail.com>

The typed set is an ordered mutable set.

When a new set is created the type for the set MUST be given.
Also a set can be created based on elements by using: \Jojo1981\TypedSet\Set::createFromElements.
The set is of a certain type and will guarantee all elements in the set are of the same type.
The type can be a primitive type or a class/interface type set for the collection.

Elements are considered as equal when the hash is the same.
The hash can be retrieved when the element is an instance of: \Jojo1981\TypedSet\HashableInterface or
when there is a handler which support the type. Handlers are classes which are implementing
the interface: \Jojo1981\TypedSet\HandlerInterface and are registered to the GlobalHandler. The HashableInterface has a higher precedence than the handlers.

The GlobalHandler is a singleton which can be configured during the bootstrap of your application.
Default handlers and custom handlers can be enabled.

When the element is an object which does not implement: HashableInterface and no handler support the
element the fallback will be that a hash will be generated based on the object hash.
This Set will be a set which has unique object instances.

Available types are:

  • int (alias integer),
  • float (aliases real, double or number)
  • string (alias text)
  • array
  • object
  • callable (alias callback)
  • iterable
  • class (class or interface name)

The \Jojo1981\TypedSet\Set class is countable and traversable (iterable).
The set has the following convenient instance methods:

  • add($element): void
  • addAll(array $elements = []): void
  • contains($element): bool
  • remove($element): void
  • clear(): void
  • isEmpty(): bool
  • isNonEmpty(): bool
  • toArray(): array
  • getType(): string
  • isEqualType(TypeInterface $type): bool
  • isEqual(Set $other): bool
  • compare(Set $other): DifferenceResult
  • map(callable $mapper, ?string $type = null): Set
  • filter(callable $predicate): Set
  • find(callable $predicate): mixed
  • all(callable $predicate): bool
  • some(callable $predicate): bool
  • none(callable $predicate): bool
  • count(): int

The \Jojo1981\TypedSet\Set has a static method createFromElements.

Installation

Library

git clone https://github.com/jojo1981/typed-set.git

Composer

Install PHP Composer

composer require jojo1981/typed-set

Basic usage

<?php

require 'vendor/autoload.php';

// Some examples on how to construct a set

$set1 = new \Jojo1981\TypedSet\Set('string', ['text1', 'text2', 'text1']);
$set1->count(); // will return 2
$set1->contains('text1'); // will return true
$set1->contains('text3'); // will return false

$set2 = \Jojo1981\TypedSet\Set::createFromElements([1, 6, 7, 1, 2, 2, 9]);
$set2->count(); // will return 5
$set2->add(7);
$set2->count(); // will return 5
$set2->add(8);
$set2->count(); // will return 6

$set3 = new \Jojo1981\TypedSet\Set(\Jojo1981\TypedSet\TestSuite\Fixture\InterfaceTestEntity::class);
$set3->addAll([new \Jojo1981\TypedSet\TestSuite\Fixture\TestEntity(), new \Jojo1981\TypedSet\TestSuite\Fixture\TestEntityBase()]);
$set1->count(); // will return 2

Configuring the GlobalHandler

<?php

require 'vendor/autoload.php';

// Optionally you can enable the default handlers before or after registering your own handlers.
\Jojo1981\TypedSet\Handler\GlobalHandler::getInstance()->addDefaultHandlers();

// Register a custom handler
\Jojo1981\TypedSet\Handler\GlobalHandler::getInstance()->registerHandler(new \Jojo1981\TypedSet\TestSuite\Fixture\PersonHandler());

jojo1981/typed-set 适用场景与选型建议

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

它主要适用于以下技术方向: 「data」 「set」 「structure」 「typed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 jojo1981/typed-set 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-09