Add new methods.
This commit is contained in:
parent
bfecefbdee
commit
42799ae6d1
|
@ -25,13 +25,16 @@ PHP_MINIT_FUNCTION(collections)
|
||||||
{
|
{
|
||||||
collection_property_name = zend_string_init("_a", strlen("_a"), 1);
|
collection_property_name = zend_string_init("_a", strlen("_a"), 1);
|
||||||
pair_first_name = zend_string_init("first", strlen("first"), 1);
|
pair_first_name = zend_string_init("first", strlen("first"), 1);
|
||||||
pair_second_name = zend_string_init("first", strlen("second"), 1);
|
pair_second_name = zend_string_init("second", strlen("second"), 1);
|
||||||
zend_class_entry collection_ce;
|
zend_class_entry collection_ce;
|
||||||
INIT_CLASS_ENTRY_EX(collection_ce, "Collection", strlen("Collection"), collection_methods);
|
INIT_CLASS_ENTRY_EX(collection_ce, "Collection", strlen("Collection"), collection_methods);
|
||||||
collections_collection_ce = zend_register_internal_class(&collection_ce);
|
collections_collection_ce = zend_register_internal_class(&collection_ce);
|
||||||
|
zend_declare_property_null(collections_collection_ce, "_a", strlen("_a"), ZEND_ACC_PRIVATE);
|
||||||
zend_class_entry pair_ce;
|
zend_class_entry pair_ce;
|
||||||
INIT_CLASS_ENTRY_EX(pair_ce, "Pair", strlen("Pair"), pair_methods);
|
INIT_CLASS_ENTRY_EX(pair_ce, "Pair", strlen("Pair"), pair_methods);
|
||||||
collections_pair_ce = zend_register_internal_class(&pair_ce);
|
collections_pair_ce = zend_register_internal_class(&pair_ce);
|
||||||
|
zend_declare_property_null(collections_pair_ce, "first", strlen("first"), ZEND_ACC_PUBLIC);
|
||||||
|
zend_declare_property_null(collections_pair_ce, "second", strlen("second"), ZEND_ACC_PUBLIC);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,19 +29,72 @@
|
||||||
#define PHP_COLLECTIONS_ERROR(type, msg) php_error_docref(NULL, type, msg)
|
#define PHP_COLLECTIONS_ERROR(type, msg) php_error_docref(NULL, type, msg)
|
||||||
#define ERR_BAD_ARGUMENT_TYPE() PHP_COLLECTIONS_ERROR(E_WARNING, "Bad argument type")
|
#define ERR_BAD_ARGUMENT_TYPE() PHP_COLLECTIONS_ERROR(E_WARNING, "Bad argument type")
|
||||||
|
|
||||||
PHP_METHOD(Collection, __construct)
|
#define ELEMENTS_VALIDATE(elements) \
|
||||||
{
|
if (IS_COLLECTION(elements)) { \
|
||||||
|
zval rv; \
|
||||||
|
(elements) = COLLECTION_FETCH(elements); \
|
||||||
|
} else if (UNEXPECTED(Z_TYPE_P(elements) != IS_ARRAY)) { \
|
||||||
|
ERR_BAD_ARGUMENT_TYPE(); \
|
||||||
|
RETVAL_NULL(); \
|
||||||
|
}
|
||||||
|
|
||||||
}
|
#define ARRAY_CLONE(dest, src) \
|
||||||
|
zend_array (dest); \
|
||||||
|
zend_hash_init(&(dest), zend_hash_num_elements(Z_ARRVAL_P(src)), NULL, ZVAL_PTR_DTOR, 0); \
|
||||||
|
zend_hash_copy(&(dest), Z_ARRVAL_P(src), NULL)
|
||||||
|
|
||||||
|
#define RETVAL_NEW_COLLECTION(collection) \
|
||||||
|
do { \
|
||||||
|
NEW_COLLECTION_OBJ(obj); \
|
||||||
|
zval retval; \
|
||||||
|
ZVAL_OBJ(&retval, obj); \
|
||||||
|
zval property; \
|
||||||
|
ZVAL_ARR(&property, collection); \
|
||||||
|
COLLECTION_UPDATE(&retval, &property); \
|
||||||
|
RETVAL_OBJ(obj); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
PHP_METHOD(Collection, __construct) {}
|
||||||
|
|
||||||
PHP_METHOD(Collection, addAll)
|
PHP_METHOD(Collection, addAll)
|
||||||
{
|
{
|
||||||
|
zval* elements;
|
||||||
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||||
|
Z_PARAM_ZVAL(elements)
|
||||||
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
ELEMENTS_VALIDATE(elements);
|
||||||
|
zval rv;
|
||||||
|
zval* current = COLLECTION_FETCH_EX();
|
||||||
|
ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(elements), zval* val)
|
||||||
|
zend_hash_next_index_insert(Z_ARRVAL_P(current), val);
|
||||||
|
ZEND_HASH_FOREACH_END();
|
||||||
|
COLLECTION_UPDATE_EX(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_METHOD(Collection, all)
|
PHP_METHOD(Collection, all)
|
||||||
{
|
{
|
||||||
|
zend_fcall_info fci;
|
||||||
|
zend_fcall_info_cache fcc;
|
||||||
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||||
|
Z_PARAM_FUNC(fci, fcc)
|
||||||
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
zval params[3], rv, retval;
|
||||||
|
fci.param_count = 3;
|
||||||
|
fci.retval = &retval;
|
||||||
|
fci.params = params;
|
||||||
|
zval* current = COLLECTION_FETCH_EX();
|
||||||
|
ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(current), Bucket* bucket)
|
||||||
|
ZVAL_COPY(¶ms[0], &bucket->val);
|
||||||
|
if (bucket->key)
|
||||||
|
ZVAL_STR(¶ms[1], bucket->key);
|
||||||
|
else
|
||||||
|
ZVAL_NULL(¶ms[1]);
|
||||||
|
ZVAL_LONG(¶ms[2], bucket->h);
|
||||||
|
zend_call_function(&fci, &fcc);
|
||||||
|
if (Z_TYPE(retval) == IS_FALSE)
|
||||||
|
RETURN_FALSE;
|
||||||
|
ZEND_HASH_FOREACH_END();
|
||||||
|
RETURN_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_METHOD(Collection, any)
|
PHP_METHOD(Collection, any)
|
||||||
|
@ -245,13 +298,7 @@ PHP_METHOD(Collection, init)
|
||||||
zval retval;
|
zval retval;
|
||||||
ZVAL_OBJ(&retval, obj);
|
ZVAL_OBJ(&retval, obj);
|
||||||
if (elements) {
|
if (elements) {
|
||||||
if (IS_COLLECTION(elements)) {
|
ELEMENTS_VALIDATE(elements);
|
||||||
zval rv;
|
|
||||||
elements = COLLECTION_FETCH(elements);
|
|
||||||
} else if (UNEXPECTED(Z_TYPE_P(elements) != IS_ARRAY)) {
|
|
||||||
ERR_BAD_ARGUMENT_TYPE();
|
|
||||||
RETVAL_NULL();
|
|
||||||
}
|
|
||||||
COLLECTION_UPDATE(&retval, elements);
|
COLLECTION_UPDATE(&retval, elements);
|
||||||
} else {
|
} else {
|
||||||
zval collection;
|
zval collection;
|
||||||
|
@ -260,7 +307,7 @@ PHP_METHOD(Collection, init)
|
||||||
COLLECTION_UPDATE(&retval, &collection);
|
COLLECTION_UPDATE(&retval, &collection);
|
||||||
zval_ptr_dtor(&collection);
|
zval_ptr_dtor(&collection);
|
||||||
}
|
}
|
||||||
ZVAL_COPY_VALUE(return_value, &retval);
|
RETVAL_OBJ(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_METHOD(Collection, intersect)
|
PHP_METHOD(Collection, intersect)
|
||||||
|
|
|
@ -15,14 +15,14 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Adds all elements of the given elements collection to this Collection.
|
* Adds all elements of the given elements collection to this Collection.
|
||||||
*
|
*
|
||||||
* @param array|Collection $elements
|
* @param array|Collection $elements
|
||||||
* @return bool
|
* @return void
|
||||||
*/
|
*/
|
||||||
function addAll($elements) {}
|
function addAll($elements) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if all elements match the given predicate.
|
* Returns true if all elements match the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function all($predicate) {}
|
function all($predicate) {}
|
||||||
|
@ -30,7 +30,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns true if at least one element matches the given predicate.
|
* Returns true if at least one element matches the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function any($predicate) {}
|
function any($predicate) {}
|
||||||
|
@ -141,7 +141,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a collection containing only elements from the given array having distinct keys
|
* Returns a collection containing only elements from the given array having distinct keys
|
||||||
* returned by the given selector function.
|
* returned by the given selector function.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $key
|
* @param callable $selector ($value, $key, $index) -> $key
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function distinctBy($selector) {}
|
function distinctBy($selector) {}
|
||||||
|
@ -166,7 +166,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a collection containing all elements except last elements that satisfy
|
* Returns a collection containing all elements except last elements that satisfy
|
||||||
* the given predicate.
|
* the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function dropLastWhile($predicate) {}
|
function dropLastWhile($predicate) {}
|
||||||
|
@ -175,7 +175,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a collection containing all elements except first elements that satisfy
|
* Returns a collection containing all elements except first elements that satisfy
|
||||||
* the given predicate.
|
* the given predicate.
|
||||||
*
|
*
|
||||||
* @param $predicate $predicate ($value, $key) -> bool
|
* @param $predicate $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function dropWhile($predicate) {}
|
function dropWhile($predicate) {}
|
||||||
|
@ -193,7 +193,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns a collection containing only elements matching the given predicate.
|
* Returns a collection containing only elements matching the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function filter($predicate) {}
|
function filter($predicate) {}
|
||||||
|
@ -201,7 +201,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns a collection containing only elements not matching the given predicate.
|
* Returns a collection containing only elements not matching the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function filterNot($predicate) {}
|
function filterNot($predicate) {}
|
||||||
|
@ -210,7 +210,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Appends all elements not matching the given predicate to the given destination.
|
* Appends all elements not matching the given predicate to the given destination.
|
||||||
*
|
*
|
||||||
* @param Collection $destination
|
* @param Collection $destination
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function filterNotTo($destination, $predicate) {}
|
function filterNotTo($destination, $predicate) {}
|
||||||
|
@ -219,7 +219,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Appends all elements matching the given predicate to the given destination.
|
* Appends all elements matching the given predicate to the given destination.
|
||||||
*
|
*
|
||||||
* @param Collection $destination
|
* @param Collection $destination
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function filterTo($destination, $predicate) {}
|
function filterTo($destination, $predicate) {}
|
||||||
|
@ -228,7 +228,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns the first element matching the given predicate, or null if no such
|
* Returns the first element matching the given predicate, or null if no such
|
||||||
* element was found.
|
* element was found.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function find($predicate) {}
|
function find($predicate) {}
|
||||||
|
@ -237,7 +237,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns the last element matching the given predicate, or null if no such
|
* Returns the last element matching the given predicate, or null if no such
|
||||||
* element was found.
|
* element was found.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function findLast($predicate) {}
|
function findLast($predicate) {}
|
||||||
|
@ -245,7 +245,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns the first element matching the given predicate.
|
* Returns the first element matching the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate[optional] ($value, $key) -> bool
|
* @param callable $predicate[optional] ($value, $key, $index) -> bool
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function first($predicate) {}
|
function first($predicate) {}
|
||||||
|
@ -254,7 +254,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a collection of all elements yielded from results of transform function
|
* Returns a collection of all elements yielded from results of transform function
|
||||||
* being invoked on each element of original collection.
|
* being invoked on each element of original collection.
|
||||||
*
|
*
|
||||||
* @param callable $transform ($value, $key) -> array|Collection
|
* @param callable $transform ($value, $key, $index) -> array|Collection
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function flatMap($transform) {}
|
function flatMap($transform) {}
|
||||||
|
@ -264,7 +264,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* original collection, to the given destination.
|
* original collection, to the given destination.
|
||||||
*
|
*
|
||||||
* @param Collection $destination
|
* @param Collection $destination
|
||||||
* @param callable $transform ($value, $key) -> array|Collection
|
* @param callable $transform ($value, $key, $index) -> array|Collection
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function flatMapTo($destination, $transform) {}
|
function flatMapTo($destination, $transform) {}
|
||||||
|
@ -299,7 +299,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Performs the given action on each element.
|
* Performs the given action on each element.
|
||||||
*
|
*
|
||||||
* @param callable $action ($value, $key) -> void
|
* @param callable $action ($value, $key, $index) -> void
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function forEach($action) {}
|
function forEach($action) {}
|
||||||
|
@ -319,7 +319,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* original array by the key returned by the given key_selector function applied to the element
|
* original array by the key returned by the given key_selector function applied to the element
|
||||||
* and returns a collection where each group key is associated with a list of corresponding values.
|
* and returns a collection where each group key is associated with a list of corresponding values.
|
||||||
*
|
*
|
||||||
* @param callable $key_selector ($value, $key) -> $new_key
|
* @param callable $key_selector ($value, $key, $index) -> $new_key
|
||||||
* @param callable $value_transform[optional] ($value) -> $new_value
|
* @param callable $value_transform[optional] ($value) -> $new_value
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
@ -331,7 +331,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* puts to the destination collection each group key associated with a list of corresponding values.
|
* puts to the destination collection each group key associated with a list of corresponding values.
|
||||||
*
|
*
|
||||||
* @param Collection $destination
|
* @param Collection $destination
|
||||||
* @param callable $key_selector ($value, $key) -> $new_key
|
* @param callable $key_selector ($value, $key, $index) -> $new_key
|
||||||
* @param callable $value_transform[optional] ($value) -> $new_value
|
* @param callable $value_transform[optional] ($value) -> $new_value
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
@ -401,7 +401,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns the last element matching the given predicate.
|
* Returns the last element matching the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate[optional] ($value, $key) -> bool
|
* @param callable $predicate[optional] ($value, $key, $index) -> bool
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function last($predicate) {}
|
function last($predicate) {}
|
||||||
|
@ -418,7 +418,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a collection containing the results of applying the given transform function
|
* Returns a collection containing the results of applying the given transform function
|
||||||
* to each element in the original collection.
|
* to each element in the original collection.
|
||||||
*
|
*
|
||||||
* @param callable $transform ($value, $key) -> Pair
|
* @param callable $transform ($value, $key, $index) -> Pair
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function map($transform) {}
|
function map($transform) {}
|
||||||
|
@ -427,7 +427,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a new collection with entries having the keys obtained by applying the transform function
|
* Returns a new collection with entries having the keys obtained by applying the transform function
|
||||||
* to each keys and values of this collection.
|
* to each keys and values of this collection.
|
||||||
*
|
*
|
||||||
* @param callable $transform ($value, $key) -> $new_key
|
* @param callable $transform ($value, $key, $index) -> $new_key
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function mapKeys($transform) {}
|
function mapKeys($transform) {}
|
||||||
|
@ -437,7 +437,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* transform function to each keys and values of this collections.
|
* transform function to each keys and values of this collections.
|
||||||
*
|
*
|
||||||
* @param Collection $destination
|
* @param Collection $destination
|
||||||
* @param callable $transform ($value, $key) -> $new_key
|
* @param callable $transform ($value, $key, $index) -> $new_key
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function mapKeysTo($destination, $transform) {}
|
function mapKeysTo($destination, $transform) {}
|
||||||
|
@ -447,7 +447,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* results to the given destination.
|
* results to the given destination.
|
||||||
*
|
*
|
||||||
* @param Collection $destination
|
* @param Collection $destination
|
||||||
* @param callable $transform ($value, $key) -> Pair
|
* @param callable $transform ($value, $key, $index) -> Pair
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function mapTo($destination, $transform) {}
|
function mapTo($destination, $transform) {}
|
||||||
|
@ -456,7 +456,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a new collection with entries having the keys of this collection and the values obtained
|
* Returns a new collection with entries having the keys of this collection and the values obtained
|
||||||
* by applying the transform function to each entry in this collection.
|
* by applying the transform function to each entry in this collection.
|
||||||
*
|
*
|
||||||
* @param callable $transform ($value, $key) -> $new_value
|
* @param callable $transform ($value, $key, $index) -> $new_value
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function mapValues($transform) {}
|
function mapValues($transform) {}
|
||||||
|
@ -466,7 +466,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* the values obtained by applying the transform function to each entry in this collection.
|
* the values obtained by applying the transform function to each entry in this collection.
|
||||||
*
|
*
|
||||||
* @param Collection $destination
|
* @param Collection $destination
|
||||||
* @param callable $transform ($value, $key) -> $new_value
|
* @param callable $transform ($value, $key, $index) -> $new_value
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function mapValuesTo($destination, $transform) {}
|
function mapValuesTo($destination, $transform) {}
|
||||||
|
@ -482,7 +482,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns the first element yielding the largest value of the given function or null if
|
* Returns the first element yielding the largest value of the given function or null if
|
||||||
* there are no elements.
|
* there are no elements.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $new_value
|
* @param callable $selector ($value, $key, $index) -> $new_value
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function maxBy($selector) {}
|
function maxBy($selector) {}
|
||||||
|
@ -507,7 +507,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns the first element yielding the smallest value of the given function or null if
|
* Returns the first element yielding the smallest value of the given function or null if
|
||||||
* there are no elements.
|
* there are no elements.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $new_value
|
* @param callable $selector ($value, $key, $index) -> $new_value
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function minBy($selector) {}
|
function minBy($selector) {}
|
||||||
|
@ -576,7 +576,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns true if no elements match the given predicate.
|
* Returns true if no elements match the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function none($predicate) {}
|
function none($predicate) {}
|
||||||
|
@ -604,7 +604,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Performs the given action on each element and returns the collection itself afterwards.
|
* Performs the given action on each element and returns the collection itself afterwards.
|
||||||
*
|
*
|
||||||
* @param callable $action ($value, $key) -> void
|
* @param callable $action ($value, $key, $index) -> void
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function onEach($action) {}
|
function onEach($action) {}
|
||||||
|
@ -621,7 +621,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* elements for which predicate yielded true, while second collection contains elements for
|
* elements for which predicate yielded true, while second collection contains elements for
|
||||||
* which predicate yielded false.
|
* which predicate yielded false.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return Pair
|
* @return Pair
|
||||||
*/
|
*/
|
||||||
function partition($predicate) {}
|
function partition($predicate) {}
|
||||||
|
@ -697,7 +697,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Removes all elements from this collection that match the given predicate.
|
* Removes all elements from this collection that match the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function removeAll($predicate) {}
|
function removeAll($predicate) {}
|
||||||
|
@ -705,7 +705,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Retains only elements of this collection that match the given predicate.
|
* Retains only elements of this collection that match the given predicate.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function retainAll($predicate) {}
|
function retainAll($predicate) {}
|
||||||
|
@ -735,7 +735,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns the single element matching the given predicate, or null if there is no or more than
|
* Returns the single element matching the given predicate, or null if there is no or more than
|
||||||
* one matching element.
|
* one matching element.
|
||||||
*
|
*
|
||||||
* @param callable $predicate ($value, $key) -> bool
|
* @param callable $predicate ($value, $key, $index) -> bool
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function single($predicate) {}
|
function single($predicate) {}
|
||||||
|
@ -766,7 +766,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Sorts elements in the collection in-place according to natural sort order of the value returned
|
* Sorts elements in the collection in-place according to natural sort order of the value returned
|
||||||
* by specified selector function.
|
* by specified selector function.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $new_value
|
* @param callable $selector ($value, $key, $index) -> $new_value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function sortBy($selector) {}
|
function sortBy($selector) {}
|
||||||
|
@ -775,7 +775,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Sorts elements in the collection in-place descending according to natural sort order of the
|
* Sorts elements in the collection in-place descending according to natural sort order of the
|
||||||
* value returned by specified selector function.
|
* value returned by specified selector function.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $new_value
|
* @param callable $selector ($value, $key, $index) -> $new_value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function sortByDescending($selector) {}
|
function sortByDescending($selector) {}
|
||||||
|
@ -806,7 +806,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a collection of all elements sorted according to natural sort order of the
|
* Returns a collection of all elements sorted according to natural sort order of the
|
||||||
* value returned by specified selector function.
|
* value returned by specified selector function.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $new_value
|
* @param callable $selector ($value, $key, $index) -> $new_value
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function sortedBy($selector) {}
|
function sortedBy($selector) {}
|
||||||
|
@ -815,7 +815,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
* Returns a collection of all elements sorted descending according to natural sort order
|
* Returns a collection of all elements sorted descending according to natural sort order
|
||||||
* of the value returned by specified selector function.
|
* of the value returned by specified selector function.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $new_value
|
* @param callable $selector ($value, $key, $index) -> $new_value
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function sortedByDescending($selector) {}
|
function sortedByDescending($selector) {}
|
||||||
|
@ -823,7 +823,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns a collection of all elements sorted descending according to their natural sort order.
|
* Returns a collection of all elements sorted descending according to their natural sort order.
|
||||||
*
|
*
|
||||||
* @param callable $selector ($value, $key) -> $new_value
|
* @param callable $selector ($value, $key, $index) -> $new_value
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function sortedDescending($selector) {}
|
function sortedDescending($selector) {}
|
||||||
|
@ -855,7 +855,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns a collection containing last elements satisfying the given predicate.
|
* Returns a collection containing last elements satisfying the given predicate.
|
||||||
*
|
*
|
||||||
* @param $predicate ($value, $key) -> bool
|
* @param $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function takeLastWhile($predicate) {}
|
function takeLastWhile($predicate) {}
|
||||||
|
@ -863,7 +863,7 @@ class Collection implements ArrayAccess, Countable
|
||||||
/**
|
/**
|
||||||
* Returns a collection containing first elements satisfying the given predicate.
|
* Returns a collection containing first elements satisfying the given predicate.
|
||||||
*
|
*
|
||||||
* @param $predicate ($value, $key) -> bool
|
* @param $predicate ($value, $key, $index) -> bool
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
function takeWhile($predicate) {}
|
function takeWhile($predicate) {}
|
||||||
|
|
12
tests/002-add-all.phpt
Normal file
12
tests/002-add-all.phpt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
--TEST--
|
||||||
|
Test Collection::addAll().
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$array = [3, 7, 5, 6, 1, 2];
|
||||||
|
$collection = Collection::init([6, 1, 2]);
|
||||||
|
$collection2 = Collection::init([3, 7, 5]);
|
||||||
|
$collection2->addAll($collection);
|
||||||
|
if ($array != $collection2->toArray())
|
||||||
|
echo 'Collection::addAll() failed.', PHP_EOL;
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
19
tests/003-all.phpt
Normal file
19
tests/003-all.phpt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
--TEST--
|
||||||
|
Test Collection::all().
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$collection = Collection::init([
|
||||||
|
"abc" => 12,
|
||||||
|
"de" => 5,
|
||||||
|
"f" => 100
|
||||||
|
]);
|
||||||
|
$result = $collection->all(function ($value) {
|
||||||
|
return $value < 100;
|
||||||
|
});
|
||||||
|
$result2 = $collection->all(function ($value, $key) {
|
||||||
|
return strlen($key) < 4;
|
||||||
|
});
|
||||||
|
if ($result || !$result2)
|
||||||
|
echo 'Collection::all() failed.', PHP_EOL;
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
Reference in New Issue
Block a user