aircury / collection
Library to provide collection structures, to use instead of arrays
Installs: 28 374
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 14
Forks: 0
Open Issues: 0
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-detached19
- 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-11-23 08:11:37 UTC
README
PHP Arrays with additional functionality. Arrays on steroids.
Usage
There are two ways of using this library. To create Collections of objects or Collections of PHP scalar types.
Object Collections
To create you own Collection, the easiest way is to copy and adjust the sample CarCollection
, replacing Car
with
the class that you need.
More generically, these are the steps to create your own Collection:
- Extend the
AbstractCollection
class - Implement on the child these methods,
getClass()
to provide information about the expected class or interface that all the objects on the collection should be.offsetGet($offset)
to specify the return class.toArray()
to provide PHPDoc information about the elements of the array.first()
to specify the return class.
Scalar type Collections
This library comes out of the box with the following Collections, ready to use:
StringCollection
StringOrNullCollection
IntegerCollection
IntegerOrNullCollection
These classes include additional expected functionality that you would expect from the data type, e.g. implode()
,
sum()
, ...
If they do not suit your needs, you can extend any of them or the AbstractScalarTypeCollection
to implement your own.