定制 jojo1981/typed-collection 二次开发

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

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

jojo1981/typed-collection

最新稳定版本:5.1.0

Composer 安装命令:

composer require jojo1981/typed-collection

包简介

Typed collection

README 文档

README

Build Status Coverage Status Latest Stable Version Total Downloads License

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

Install PHP 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

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固