Download the PHP package tobento/service-collection without Composer
On this page you can find all versions of the php package tobento/service-collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/service-collection
More information about tobento/service-collection
Files in tobento/service-collection
Package service-collection
Short Description Fluent and convenient wrapper classes for working with arrays of data.
License MIT
Homepage https://www.tobento.ch
Informations about the package service-collection
Collection Service
The Collection Service provides fluent and convenient wrapper classes for working with arrays of data.
Table of Contents
- Getting started
- Requirements
- Highlights
- Documentation
- Collection
- Translations
- Credits
Getting started
Add the latest version of the collection service running this command.
Requirements
- PHP 8.0 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
Documentation
Collection
Method | Description | Dot Notation Supported |
---|---|---|
add() | Add an item value if it does not exist or is null. | yes |
all() | Get all items. | - |
any() | Check if at least one of the items exists. | yes |
combine() | Combine item values with item keys. | no |
count() | Counts the items. | - |
delete() | Delete an item by key. | yes |
empty() | Check whether collection or an item is empty. | yes |
except() | Get all items except the keys specified. | yes |
filter() | Filter items. | - |
first() | Get first item passing a given truth test. | - |
flatten() | Flatten array to single level array. | - |
get() | Get an item value by key. | yes |
has() | Check if an item by key exists. | yes |
keys() | Gets the item keys. First array level only. | no |
last() | Get last item passing a given truth test. | - |
map() | Map over each of the items. | - |
merge() | Merge items. | no |
mergeRecursive() | Merge items recursive. | no |
only() | Get only the items from the keys specified. | yes |
onlyPresent() | Get only the items present from the keys specified. | yes |
replace() | Replace the items. | - |
replaceRecursive() | Replace the items recursive. | - |
set() | Set an item value by key. | yes |
setAll() | Set all items. | no |
toArray() | Converts the collection into a plain PHP array. | - |
toJson() | Converts the collection into a JSON serialized string. | - |
union() | Same as merge, except existing items got not overwritten. | - |
values() | Gets the item values. | - |
add()
Add an item value if it does not exist or is null.
all()
Get all items from the collection.
any()
Check if at least one of the items exists.
combine()
Combine item values with item keys.
count()
Counts the items.
delete()
Delete an item by key.
empty()
Check whether collection or an item is empty.
except()
Get all items except the keys specified.
filter()
Filter items.
first()
Get first item passing a given truth test.
flatten()
Flatten array to single level array.
get()
Get an item value by key.
has()
Check if an item by key exists.
keys()
Gets the item keys. First array level only.
last()
Get last item passing a given truth test.
map()
Map over each of the items.
merge()
Merge items.
mergeRecursive()
Merge items recursive.
only()
Get only the items from the keys specified.
onlyPresent()
Get only the items present from the keys specified.
replace()
Replace the items.
replaceRecursive()
Replace the items recursive.
set()
Set an item value by key.
setAll()
Set all items.
toArray()
Converts the collection into a plain PHP array.
toJson()
Converts the collection into a JSON serialized string.
union()
Same as merge, except existing items got not overwritten.
values()
Gets the item values.
Translations
Create a new Translations collection.
setAll()
Set all translations. This would overwrite all previous translations.
set()
Set translation(s) value by key.
add()
Add translation(s) value by key if it does not exist or is null.
get()
Get value for default locale:
Get value for specific locale:
Get values for current locales:
Get values for specific locales:
has()
If translation(s) by key exist.
all()
Get all translation(s).
delete()
Delete translation(s) by key.
deleteAll()
Delete all translation(s).
toArray()
toJson()
Credits
- Tobias Strub
- All Contributors
Idea and some code snippets is taken from Collections of the Laravel framework.