Skip to content

Commit

Permalink
Refactoring collection
Browse files Browse the repository at this point in the history
BC breaks
 * removed previously deprecated methods
 * each() now consistent with Laravel / other each() implementations
 * isModified() removed
  • Loading branch information
Dave Redfern committed Jun 23, 2017
1 parent 13bf785 commit 387ef3e
Show file tree
Hide file tree
Showing 14 changed files with 1,068 additions and 695 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Change Log
==========

2017-06-23
----------

* changed each() to mirror other Collection each implementations - BC break!
* changed methods that accept arrays to use convertToArray()
* changed call() to transform() - call() is now deprecated
* removed all previously deprecated methods
* removed static factory methods to a factory class (except collect())
* removed modified flag
* added assert()
* added only()
* added partition()
* added value()
* extracted some method groups into traits

2017-04-17
----------

Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ If you see something missing or have suggestions for other methods, submit a PR

### Requirements

* PHP 5.6+
* PHP 7+

### Installation

Expand Down Expand Up @@ -46,21 +46,22 @@ The Collection supports array access and iteration.

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

The Collection maintains an internal "dirty" flag that is changed when the collection is modified.

Nested arrays are automatically converted to new Collections when accessed.

#### Other Notes

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

### Available Methods

#### Static Methods
#### Factory Methods

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

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

### Deprecated Methods

* call() use transform()

#### Removed from v2

* isValueInSet() use contains()
* addIfNotInSet() use add()
* findByRegex() use match()
* findByRegex() use match()
* isModified() - removed from v2
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=7"
},
"require-dev": {
"phpunit/phpunit": "~5.6"
"phpunit/phpunit": "~6.2"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 387ef3e

Please sign in to comment.