T17000 collection revamp#17009
Open
niden wants to merge 15 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello!
In raising this pull request, I confirm the following:
Notable changes:
Phalcon\Support\Collection::__construct()to accept two additional opt-in parameters —bool $strictNull = falseand?string $type = null. WhenstrictNullistrue,get()returns storednullvalues verbatim instead of substituting the default (previous behavior was unconditional default-substitution); whentypeis set, everyset()/init()runs through the newvalidateType()guard, which maps the scalar tokensint/string/bool/float/array/objectto theiris_*checks and treats anything else as a class/interface name compared withinstanceof, throwingInvalidArgumentExceptionon mismatchPhalcon\Support\Collection::__serialize()to return a structured array["data", "insensitive", "strictNull", "type"]so a serialize/unserialize round-trip restores the full configuration (previously onlydatasurvived).__unserialize()accepts both the new structured format and the legacy flat-array format, so existing serialized blobs keep deserializing without interventionPhalcon\Support\Collection::getKeys()andPhalcon\Support\Collection::getValues()to delegate to the newkeys()/values()methods and marked theget*-prefixed pair@deprecated; behavior is unchanged but new code should callkeys()/values()insteadPhalcon\Contracts\Support\Collectionto declare the expanded method surface (column,each,filter,first,getType,isEmpty,keys,last,map,reduce,replace,sort,values,where) so the contract matches the implementationPhalcon\Support\Collection:column(string $propertyOrMethod): array(lift a single property/method off every item, keyed by the original collection key)Phalcon\Support\Collection:each(callable $callback)(run the callback for side effects and return$thisfor chaining)Phalcon\Support\Collection:filter(callable $callback)(new collection of items where the callback returns truthy)Phalcon\Support\Collection:first()/last()(head/tail value ornullon empty)Phalcon\Support\Collection:isEmpty(): bool,getType(): string|null(the type guard configured at construction)Phalcon\Support\Collection:keys(bool $insensitive = true)andvalues()(the non-get-prefixed names, withgetKeys/getValuesretained as deprecated wrappers)Phalcon\Support\Collection:map(callable $callback)(new collection of transformed values, keys preserved)Phalcon\Support\Collection:reduce(callable $callback, mixed $initial = null): mixed(callback signature($accumulator, $value, $key))Phalcon\Support\Collection:replace(array $data): void(clear theninitin one call)Phalcon\Support\Collection:sort(?callable $callback = null, int $order = SORT_ASC)(uasortwhen a callback is supplied, otherwiseasort/arsortkeyed by$order)Phalcon\Support\Collection:where(string $propertyOrMethod, mixed $value)(strict-equality filter viaextractValue)Thanks