Le ven. 12 juil. 2024 à 12:55, Benjamin Außenhofer <kont...@beberlei.de> a écrit :
> > > Am 21.06.2024, 12:24:20 schrieb Nicolas Grekas < > nicolas.grekas+...@gmail.com>: > >> Hi Ben, >> >> On Tue, Jun 18, 2024, at 5:45 PM, Arnaud Le Blanc wrote: >>>>> > Hi Larry, >>>>> > >>>>> > Following your feedback we propose to amend the API as follows: >>>>> > >>>>> > ``` >>>>> > class ReflectionClass >>>>> > { >>>>> > public function newLazyProxy(callable $factory, int $options): >>>>> object {} >>>>> > >>>>> > public function newLazyGhost(callable $initializer, int >>>>> $options): object {} >>>>> > >>>>> > public function resetAsLazyProxy(object $object, callable >>>>> > $factory, int $options): void {} >>>>> > >>>>> > public function resetAsLazyGhost(object $object, callable >>>>> > $initializer, int $options): void {} >>>>> > >>>>> > public function initialize(object $object): object {} >>>>> > >>>>> > public function isInitialized(object $object): bool {} >>>>> > >>>>> > // existing methods >>>>> > } >>>>> > >>>>> > class ReflectionProperty >>>>> > { >>>>> > public function setRawValueWithoutInitialization(object $object, >>>>> > mixed $value): void {} >>>>> > >>>>> > public function skipInitialization(object $object): void {} >>>>> > >>>>> > // existing methods >>>>> > } >>>>> > ``` >>>>> > >>>>> > Comments / rationale: >>>>> > - Adding methods on ReflectionClass instead of ReflectionObject is >>>>> > better from a performance point of view, as mentioned earlier >>>>> > - Keeping the word "Lazy" in method names is clearer, especially for >>>>> > "newLazyProxy" as a the "Proxy" pattern has many uses-cases that are >>>>> > not related to laziness. However we removed the word "Instance" to >>>>> > make the names shorter. >>>>> > - We have renamed "make" methods to "reset", following your feedback >>>>> > about the word "make". It should better convey the behavior of these >>>>> > methods, and clarify that it's modifying the object in-place as well >>>>> > as resetting its state >>>>> > - setRawValueWithoutInitialization() has the same behavior as >>>>> > setRawValue() (from the hooks RFC), except it doesn't trigger >>>>> > initialization >>>>> > - Renamed $initializer to $factory for proxy methods >>>>> > >>>>> > WDYT? >>>>> > >>>>> > Best Regards, >>>>> > Arnaud >>>>> >>>>> Oh, that looks *so* much more self-explanatory and readable. I love >>>>> it. Thanks! (Looks like the RFC text hasn't been updated yet.) >>>>> >>>> >>>> Happy you like it so much! The text of the RFC is now up to date. Note >>>> that we renamed ReflectionProperty::skipInitialization() and >>>> setRawValueWithoutInitialization() to skipLazyInitialization() and >>>> setRawValueWithoutLazyInitialization() after we realized that >>>> ReflectionProperty already has an isInitialized() method for something >>>> quite different. >>>> >>>> While Arnaud works on moving the code to the updated API, are there >>>> more comments on this RFC before we consider opening the vote? >>>> >>> >>> Thank you for updating the API, the RFC is now much easier to grasp. >>> >>> >>> My few comments on the updated RFC: >>> >>> >>> 1 ) ReflectionClass API is already very large, adding methods should use >>> naming carefully to make sure that users identify them as belonging to a >>> sub.feature (lazy objects) in particular, so i would prefer we rename some >>> of the new methods to: >>> >>> >>> isInitialized => isLazyObject (with inverted logic) >>> >>> initialize => one of initializeLazyObject / initializeWhenLazy / >>> lazyInitialize - other methods in this RFC are already very outspoken, so I >>> don’t mind being very specific here as well. >>> >>> >>> The reason is „initialized“ is such a generic word, best not have API >>> users make assumptions about what this relates to (readonly, lazy, …) >>> >> >> I get this aspect, I'm fine with either option, dunno if anyone has a >> strong preference? >> Under this argument, mine is isLazyObject + initializeLazyObject. >> > > The RFC still has the isInitialized and initialize methods, lets go with > your suggestions isLazyObject, initializeLazyObject, and also maybe > markLazyObjectAsInitialized instead of markAsInitialized? > I've updated the RFC with these method names. I've a slight preference towards shorter names that don't contain the "lazy object" wording but I feel like the consensus might be to have the more explicit versions, so fine to me.