jojo1981/typed-set
Composer 安装命令:
composer require jojo1981/typed-set
包简介
Typed set
关键字:
README 文档
README
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
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jojo1981/typed-set 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Simple, immutable data structures
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
Baum is an implementation of the Nested Set pattern for Eloquent models.
Extension provide very simply use enum for models (and others) in yii2
统计信息
- 总下载量: 18.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-09