-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Description
Currently, users are not able to extend Collection. They can create a Collection instance by passing a custom iterator that wraps the previous collection, but they cannot chain calls. They have to re-wrap manually each time.
Even if users could extend Collection without breaking, the current modifiers return CollectionInterface that's implemented by various other classes and does not return static.
Making collections extensible requires these changes:
- Combine
CollectionInterfaceandCollectionTraitintoCollection - Change built-in iterators to be standard Interface implementations and not extend Collection
- Change
Collectionto returnnew static()which wraps one of the iterators - Add helper method to use a custom iterator without extending Collection
Users would have to make these changes:
- Change
CollectionInterfacetype declarations toCollection - Get the inner iterator before calling
printer()on theTreeIterator
This allows future changes:
- Allow the user to specify the result set class that extends Collection
- Allow adding methods to Collection without modifying an interface
Collection cannot be extended because it has confusing logic trying to determine if it's a standard Collection or an iterator extending Collection. Any user class that extends Collection breaks this logic and fails to unwrap properly.
Unknown:
- Do we need to perform the full unwrapping of inner iterators
CakePHP Version
6.0