aircury / collection
提供集合结构的库,用于替代数组
dev-master
2024-07-26 12:11 UTC
Requires
- php: ^8.3
- clue/graph: ^0.9.3
- graphp/algorithms: ^0.8.2
Requires (Dev)
- phpspec/prophecy-phpunit: ^2.2
- phpunit/phpunit: ^11.2
- dev-master
- dev-AL-4306
- dev-AL-4844
- dev-AL-4850-micromatch
- dev-AL-4858
- dev-AL-4865
- dev-AL-4872
- dev-AL-4878-path-to-regexp-ignore
- dev-AL-4979-twig-ignore
- dev-VPN
- dev-grype-ignore
- dev-ignore-auth-vulnerabilities
- dev-collection_phpunit_upgrade
- dev-revert-9-collection_fix_other_mixed_deprecation_warning
- dev-collection_upgrade_php8.3
- dev-collection_fix_mixed_deprecation_warning
- dev-implementations-vpn
- dev-vpn-ambition
- dev-collection_fix_composer_lock_for_upgrade_php_8
- dev-connector_upgrading_php
- dev-ambition_dfe_npq_declarations_automation
- dev-c+_fix_using_$this_when_not_in_object_context_error
- dev-detached
- dev-detached10
- dev-detached11
- dev-detached12
- dev-detached13
- dev-detached14
- dev-detached15
- dev-detached16
- dev-detached17
- dev-detached18
- dev-detached2
- dev-detached3
- dev-detached4
- dev-detached5
- dev-detached6
- dev-detached7
- dev-detached8
- dev-detached9
- dev-eanr_al_2398_rebuilt
- dev-ecf_started_2023_erx_app_view
- dev-vault_cypress
- dev-admissions+_config_files
- dev-bi_56_fix
- dev-code_notify_errors
- dev-connector_view_migrations
- dev-tasks_juanjo
This package is auto-updated.
Last update: 2024-09-13 06:35:34 UTC
README
PHP 数组带额外功能。增强版的数组。
使用方法
使用此库有两种方式。创建对象集合或 PHP 标量类型集合。
对象集合
要创建自己的集合,最简单的方法是复制并调整示例 CarCollection
,将 Car
替换为你需要的类。
更通用的步骤创建自己的集合
- 扩展
AbstractCollection
类 - 在子类中实现以下方法,
getClass()
提供关于集合中所有对象期望的类或接口的信息。offsetGet($offset)
指定返回的类。toArray()
提供关于数组元素 PHPDoc 的信息。first()
指定返回的类。
标量类型集合
此库自带以下集合,可直接使用
StringCollection
StringOrNullCollection
IntegerCollection
IntegerOrNullCollection
这些类包含了你从数据类型期望的额外功能,例如 implode()
、sum()
等。
如果它们不符合你的需求,你可以扩展它们中的任何一个或 AbstractScalarTypeCollection
来实现自己的。