Review main Merged

46961[FEATURE] Allow calling toArray() on ObjectStorage using name getArray()

Claus Due CR +2 V +2 Easy +37 −1 updated 03/05/16, 19:48

Commit message

This change adds an alias method which allows ObjectStorage's
values to be accessed using a "get"-prefixed method name which
in turn allows the values to be addressed using numerical
indices or converted to arrays on-the-fly by adding an ".array"
segment to the property path.

Review

  • Code review CR +2
    • Benni Mack +2
    • Oliver Hader +1
  • Verified V +2
    • Benni Mack +2
    • Oliver Hader +1

Issues 1

Files 3

Review log 15

  1. Claus Due uploaded patch set 1 02/29/16, 14:23

  2. Frank Nägler commented on patch set 1 02/29/16, 14:41

    I think it is the wrong way to put the repository into the view to access the data. If you will display only one record, then add this one the view. I would prefer to not merge this.
  3. Claus Due commented on patch set 1 02/29/16, 14:44

    Not sure I understand - this doesn't imply that you put the repository in the view, it only implies that you can access ObjectStorage as an array - and ObjectStorages can appear for example as child properties on an array. Has ties to https://forge.typo3.org/issues/73717; being able to access as array using virtual getter which matches expected conventions would mitigate this problem.
  4. Claus Due commented on patch set 1 02/29/16, 14:44

    "child properties on an array" -> "child properties on an object"
  5. Frank Nägler commented on patch set 1 02/29/16, 14:57

    In case you have an ObjectStorage as a property, you could iterate with the f:for VH over this ObjectStorage. example: <f:for each="{records}" as="record"> <f:for each="{record.categories}" as="caregory"> // do anything </f:for> </f:for> I can't see a benefit by accessing the data. And I can't see a solution for the second issue you linked here. They could/will still have different indexes.
  6. Marius Wieschollek commented on patch set 1 03/04/16, 14:08

    I would agree with Frank Naegler. If you want to access a specific record you should assign it to the view in the controller. Also I would prefer to make either all the to*-Methods available trough ObjectAccess or not at all. With this change it could seem like you could access ".array" on every kind of object and it would be confusing if it doesn't work for anything other than the ObjectStorage.
  7. Claus Due commented on patch set 1 03/04/16, 14:18

    @Marius/Frank, the point being "accessing a single item" is misunderstood, that's not the intention of this patch. The idea is to become able to reference this ObjectStorage explicitly as an array not just in a View but indeed anywhere ObjectAccess gets used (which includes things like controller argument mapping). The suggestion to put this in ObjectStorage is valid but not ideal. It would cause one additional method check for *every* time any context uses the ObjectAccess method. That's excessive, given that the goal is to be able to do this with ObjectStorage which is at this time the only candidate we have for this accessing problem. There's a much longer discussion about this in slack as well. But in summary: I wouldn't over-engineer this and it is merely a couple of added lines not affecting any interface or such. The benefit far outweighs the arguments against it, imho.
  8. Nicole Hummel commented on patch set 1 03/04/16, 15:02

    Can you add tests for that, please? What do you think in general the expand the property finder to support "to" prefix of a property name (like get, is, has). That would allow the usage of other methods as well without having umbrella functions.
  9. Claus Due commented on patch set 1 03/04/16, 20:49

    @NIcole yes, will add a test that it delegates correctly. About expanding ObjectAccess to support additional prefixes I would say no in every case that isn't "get" or "is", and I only accept "is" reluctantly. IMHO ObjectAccess is used so frequently and widely that what we should be doing is removing things from it and making it perform better (I have another pull request aiming at that but it's pretty old by now). The fact that it already supports "has" and does magic to SplObjectstorage is IMHO an eyesore, unnecessary performance drain just for edge case support.
  10. Nicole Hummel commented on patch set 1 03/04/16, 21:00

    Thank you for your answer. Fine with it ;-)
  11. Oliver Hader uploaded patch set 2 03/05/16, 18:51

  12. Oliver Hader voted on patch set 2 CR +1 V +1 03/05/16, 18:51

  13. Oliver Hader commented on patch set 2 03/05/16, 18:52

  14. Benni Mack voted on patch set 2 CR +2 V +2 03/05/16, 19:48

  15. Gerrit merged patch set 2 03/05/16, 19:48