jojo1981/typed-collection
Composer 安装命令:
composer require jojo1981/typed-collection
包简介
Typed collection
关键字:
README 文档
README
Author: Joost Nijhuis <jnijhuis81@gmail.com>
The typed collection is an ordered mutable sequence.
It is a data structure which is in fact a wrapper around an indexed array.
When a new collection is created the type for the collection MUST be given.
The collection is of a certain type and will guarantee all elements in the collection are of the same type.
The type can be a primitive type or a class/interface type set for the collection.
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\TypedCollection\Collection class is countable and is traversable (iterable).
The collection has the following convenient instance methods:
- getType(): string
- isEqualType(Collection $otherCollection): bool
- isEmpty(): bool
- isNonEmpty(): bool
- unshiftElement($element): void
- pushElement($element): void
- shiftElement()
- popElement()
- hasElement($element): bool
- pushElements(array $elements): void
- unshiftElements(array $elements): void
- setElements(array $elements): void
- removeElement($element): void
- indexOfElement($element): ?int
- getElementByIndex(int $index)
- getFirstElement()
- getLastElement()
- getFirstElementAsCollection(): Collection
- toArray(): array
- sortBy(callable $comparator): Collection
- map(string $type, callable $mapper): Collection
- flatMap(string $type, callable $mapper): Collection
- merge(Collection $otherCollection, Collection ...$otherCollections): void
- all(callable $predicate): bool
- some(callable $predicate): bool
- none(callable $predicate): bool
- forEach(callable $callback): void
- foldLeft(callable $callback, $initial = null)
- foldRight(callable $callback, $initial = null)
- filter(callable $predicate): Collection
- find(callable $predicate)
- group(callable $predicate, callable ...$predicates): Collection
- partition(callable $predicate): Collection
- slice(int $offset, ?int $length = null): Collection
- clear(): void
- count(): int
- getIterator(): CollectionIterator
- isEqualCollection(Collection $otherCollection, ?callable $predicate = null, bool $strict = false): bool
The \Jojo1981\TypedCollection\Collection has a static method createFromCollections.
Multiple collection of the same type can be merged together into one collection.
Installation
Library
git clone https://github.com/jojo1981/typed-collection.git
Composer
composer require jojo1981/typed-collection
Basic usage
<?php require 'vendor/autoload.php'; // Create an empty collection of type `string` $collection1 = new \Jojo1981\TypedCollection\Collection('string'); // Create a collection of type `integer` with some elements $collection2 = new \Jojo1981\TypedCollection\Collection('int', [1, 2, 3]); // Will throw an exception, because an invalid type has been given try { $collection = new \Jojo1981\TypedCollection\Collection('invalid'); } catch (\Jojo1981\TypedCollection\Exception\CollectionException $exception) { echo $exception->getMessage() . PHP_EOL; } // Create a collection of class type \stdClass $collection3 = new \Jojo1981\TypedCollection\Collection(\stdClass::class); $collection3->pushElement(new \stdClass()); try { $collection3->pushElement('element'); } catch (\Jojo1981\TypedCollection\Exception\CollectionException $exception) { echo $exception->getMessage() . PHP_EOL; } echo 'Collection count: ' . $collection3->count() . PHP_EOL; // Will be 1
jojo1981/typed-collection 适用场景与选型建议
jojo1981/typed-collection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.36k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「data」 「structure」 「collection」 「typed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jojo1981/typed-collection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jojo1981/typed-collection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jojo1981/typed-collection 相关的其它包
同方向 / 同关键字的高下载量 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
This package provides type-safe extension of the laravel collection, forcing a single type of object.
Extension provide very simply use enum for models (and others) in yii2
统计信息
- 总下载量: 20.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-30