Review main Abandoned

49874[FEATURE] Add support for PHPdoc array types in extbase PropertyMapper

Markus Hölzle CR 0 V 0 Normal +111 −1 updated 02/11/18, 00:32

Commit message

Support PHPdoc array type notation with square brackets like int[],
bool[] or MyObject[] in extbase PropertyMapper class.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 3

Review log 2127

Show 12 earlier messages
  1. Markus Hölzle uploaded patch set 1 09/06/16, 17:33

  2. TYPO3com voted on patch set 1 V +1 09/06/16, 17:37 Completed build in 03m 17s on Tue, 6 Sep, 07:37 PM Test Summary: 18507 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3006

  1. Mathias Brodala commented on patch set 1 09/07/16, 06:32

    I generally like the idea but I wonder if this could be achieved with the ArrayConverter instead using a similar logic like the ObjectStorageConverter.

    PropertyMapper.php:124

    Why referencing here?
  2. Markus Hölzle commented on patch set 1 09/07/16, 06:48

    A converter like the "ObjectStorageConverter" isn't possible so far, because extbase always tries to find a matching class name. Just one fix class name and nothing generic is allowed here (See variable "$targetType" in "ObjectStorageConverter" for example). So we have to add a TypeConverter for each possible array type (IntArrayConverter, StringArrayConverter, ...), but I think this is a bad idea. Referencing variables is just a habit of mine to save some RAM :-)
  3. Mathias Brodala commented on patch set 1 09/07/16, 06:52

    Well, if Foo[] would be split in doMapping(), one could allow for the ArrayConverter to be invoked. That converter could then return the type of its child properties thanks to the original $targetType. In any case you should not use the reference operator for performance reasons since it can have unexpected side effecs.
  4. Benni Mack commented on patch set 1 09/07/16, 09:02

    hey markus, nice one. could we have tests for that please?
  5. Oliver Klee commented on patch set 1 09/14/16, 13:29

    We absolutely need unit tests for this.
  6. Markus Hölzle uploaded patch set 2 10/08/16, 10:13

  7. Markus Hölzle uploaded patch set 3 10/08/16, 10:14

  8. TYPO3com voted on patch set 2 V +1 10/08/16, 10:17 Completed build in 03m 34s on Sat, 8 Oct, 12:16 PM Test Summary: 18547 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3444

  9. TYPO3com voted on patch set 3 V +1 10/08/16, 10:17 Completed build in 02m 41s on Sat, 8 Oct, 12:17 PM Test Summary: 18547 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3445

  10. Claus Due commented on patch set 3 10/18/16, 00:44

    Correct me if I am wrong here, but: Is this not much more appropriately solved by declaring the function as `setFoobars(array $foobars)`? If I recall, this makes the signature-level requirement take precedence over the phpdoc requirement, giving the result that both IDE and Extbase will consume the value correctly without the need for a new [FEATURE].
  11. Markus Hölzle commented on patch set 3 10/26/16, 08:37

    Such a feature is required for type-safe PHP progamming. For example: If you want an array with integers extbase will validate this for you. Modern IDE's like PhpStorm are using the PhpDoc here as expected. A PHP native solution for this exists as draft: https://wiki.php.net/rfc/generic-arrays
  12. Claus Due commented on patch set 3 10/26/16, 22:43

    I still think this doesn't belong in the PropertyMapper like this. Perhaps in the ArrayConverter or as a new type of converter, e.g. TypedArrayConverter, which would recursively convert to *whichever* type you specify as the nested type. Just as an example, PropertyMapper doesn't even directly support the Extbase format of nested types - it only understands how to extract the nested type and ignore the container type (which is handled by the ObjectStorageConverter; it then iterates and converts child objects to the desired nested type). So architecturally this really does not belong here in the PropertyMapper directly. I also am of the opinion that this clashes quite a bit with the Extbase convention of using `array<string>` (actually there's a usage in PropertyMapper itself, case in point). Personally I prefer the `[]` syntax not least because it is IDE compatible but it would introduce inconsistency. But "prior art" is currently NOT in this format. As a TypedArrayConverter I guess it could be argued, but as an additional low-level syntax support... probably not.

    PropertyMapper.php:121

    This needs a better exception message, for example including the original target type. Also: any Traversable or array can be converted using the logic below so we don't necessarily need to enforce an array. The output will always be an array - and that's fine.

    PropertyMapper.php:125

    substr($targetType, 0, -2) gets called with the same input arguments for every element in $source; extract to variable outside loop.
  13. Markus Hölzle uploaded patch set 4 02/22/17, 12:37

  14. TYPO3com voted on patch set 4 V -1 02/22/17, 12:44 Completed build in 07m 08s on Wed, 22 Feb, 01:44 PM Test Summary: 6 of 56393 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8368

  15. Markus Hölzle uploaded patch set 5 02/22/17, 13:13

  16. TYPO3com voted on patch set 5 V -1 02/22/17, 13:19 Completed build in 06m 02s on Wed, 22 Feb, 02:19 PM Test Summary: 56393 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8369

  17. Markus Hölzle uploaded patch set 6 02/22/17, 14:06

  18. TYPO3com voted on patch set 6 V +1 02/22/17, 14:15 Completed build in 08m 43s on Wed, 22 Feb, 03:15 PM Test Summary: 56393 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8370

  19. Matthias Vogel voted on patch set 6 CR +1 09/08/17, 19:45

  20. Benni Mack voted on patch set 6 CR +2 09/20/17, 14:50

  21. Frank Nägler voted on patch set 6 CR +1 09/22/17, 09:26

  22. Claus Due commented on patch set 6 CR -1 09/22/17, 09:52

    I still do not believe this should be added here, rather it should be a converter on its own. This is removing the logic that maps compound objects, from the TypeConverter to the PropertyMapper. I will not be able to make a TypeConverter after this which targets such compound types, because this will now be forced to happen outside of TypeConverters with no way to affect it. I must object, hence a -1 from me hoping that prevents it from being merged...
  23. Benni Mack commented on patch set 6 CR 0 09/22/17, 12:17

    @Markus what do you think?
  24. Alexander Schnitzler commented on patch set 6 11/28/17, 12:47

    I very much agree with what Claus says. The idea of integrating that as a TypedArrayConverter is a good one, changing the syntax only in the property mapper while leaving the old syntax active for ObjectStorage relations in models is a bit chaotic and might be quite confusing.
  25. Benni Mack abandoned the change 02/11/18, 00:32

    abandoned, as another solution is preferred.