Skip to content

Commit 387ef3e

Browse files
author
Dave Redfern
committed
Refactoring collection
BC breaks * removed previously deprecated methods * each() now consistent with Laravel / other each() implementations * isModified() removed
1 parent 13bf785 commit 387ef3e

File tree

14 files changed

+1068
-695
lines changed

14 files changed

+1068
-695
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
Change Log
22
==========
33

4+
2017-06-23
5+
----------
6+
7+
* changed each() to mirror other Collection each implementations - BC break!
8+
* changed methods that accept arrays to use convertToArray()
9+
* changed call() to transform() - call() is now deprecated
10+
* removed all previously deprecated methods
11+
* removed static factory methods to a factory class (except collect())
12+
* removed modified flag
13+
* added assert()
14+
* added only()
15+
* added partition()
16+
* added value()
17+
* extracted some method groups into traits
18+
419
2017-04-17
520
----------
621

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If you see something missing or have suggestions for other methods, submit a PR
88

99
### Requirements
1010

11-
* PHP 5.6+
11+
* PHP 7+
1212

1313
### Installation
1414

@@ -46,21 +46,22 @@ The Collection supports array access and iteration.
4646

4747
The Collection supports __call() that proxies through to invoke() allowing methods to be called on all object items.
4848

49-
The Collection maintains an internal "dirty" flag that is changed when the collection is modified.
50-
5149
Nested arrays are automatically converted to new Collections when accessed.
5250

5351
#### Other Notes
5452

55-
This Collection does not allow adding duplicate values to the Collection. They can be set
53+
This Collection does not allow adding duplicate values in the Collection. They can be set
5654
on create, but calls to add() or offsetSet() will ignore the value.
5755

5856
### Available Methods
5957

60-
#### Static Methods
58+
#### Factory Methods
6159

6260
* collect() create a new Collection statically
61+
* collectionFromIniString() create a Collection from an ini style string
6362
* collectionFromString() split an encoded string into a Collection
63+
* collectionFromUrl() given a URL returns a Collection after using parse_url()
64+
* collectionFromUrlQuery() converts a URL query string to a Collection using parse_str()
6465
* convertToArray() attempts to convert the variable to an array
6566
* explode() explode a string into a Collection
6667

@@ -69,12 +70,13 @@ on create, but calls to add() or offsetSet() will ignore the value.
6970
* add() add a value (auto-key), only if it does not exist
7071
* all() returns the underlying array
7172
* append() adds the values to the end of the Collection
72-
* call() applies the callback to all items returning a new Collection with the same keys and the values from the callback
73+
* assert() returns true if all elements pass the test, false on first failure
74+
* call() alias of transform()
7375
* contains() does the collection have the value
7476
* count() returns the number of items in the Collection
7577
* diff() returns the items not present in the past collection of items
7678
* diffKeys() returns the keys not present in the past collection of items
77-
* each() synonym of walk() apply a callback to each item (by reference), returns a new Collection
79+
* each() applies the callback to all items in the set; if the callback fails stops iterating
7880
* except() filters out the specified keys, returning a new Collection
7981
* filter() filter the Collection by a callback
8082
* fill() create a Collection filled with a value
@@ -92,7 +94,6 @@ on create, but calls to add() or offsetSet() will ignore the value.
9294
* implodeKeys() join the keys together with the glue string
9395
* intersect() returns a Collection of items that exist in the past items
9496
* invoke() call a method on all objects in the Collection
95-
* isModified() has the Collection been modified since instantiation
9697
* keys() returns all the keys in a new Collection
9798
* last() returns the last item
9899
* lower() converts all values to lowercase, returns a new Collection
@@ -101,6 +102,7 @@ on create, but calls to add() or offsetSet() will ignore the value.
101102
* max() find the largest value in the collection (optionally by key/callable)
102103
* min() find the smallest value in the collection (optionally by key/callable)
103104
* merge() combine items into the current Collection, replaces existing keys items
105+
* only() returns only these keys in a new Collection
104106
* pad() pad the Collection to a size
105107
* pop() removes an item from the end of the Collection
106108
* reduce() applies a callback to the Collection to produce a single value
@@ -120,14 +122,21 @@ on create, but calls to add() or offsetSet() will ignore the value.
120122
* sum() sum values in collection, optionally by key or callable
121123
* toArray() convert to an array, cascades through values casting sub-Collections to array
122124
* toJson() convert to a JSON string, uses toArray() internally
125+
* transform() applies the callback to all items returning a new Collection with the same keys and the values from the callback
123126
* trim() remove whitespace surrounding all values
124127
* unique() creates a new Collection containing only unique values
125128
* upper() converts all values to uppercase, returns a new Collection
129+
* value() similar to get() except returns the default if the returned value is empty
126130
* values() returns a new Collection containing just the values
127131
* walk() applies a callback to each item, returns a new Collection (uses array_walk)
128132

129133
### Deprecated Methods
130134

135+
* call() use transform()
136+
137+
#### Removed from v2
138+
131139
* isValueInSet() use contains()
132140
* addIfNotInSet() use add()
133-
* findByRegex() use match()
141+
* findByRegex() use match()
142+
* isModified() - removed from v2

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=5.6.0"
17+
"php": ">=7"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "~5.6"
20+
"phpunit/phpunit": "~6.2"
2121
},
2222
"autoload": {
2323
"psr-4": {

0 commit comments

Comments
 (0)