Add ArrayType as a generic wrapper for a "list of custom types"#6883
Add ArrayType as a generic wrapper for a "list of custom types"#6883mpdude wants to merge 1 commit intodoctrine:4.3.xfrom
ArrayType as a generic wrapper for a "list of custom types"#6883Conversation
| * @param int|string $key The key of the bound parameter type | ||
| */ | ||
| public function getParameterType(int|string $key): string|ParameterType|Type|ArrayParameterType | ||
| public function getParameterType(int|string $key): string|ParameterType|Type|ArrayParameterType|ArrayType |
There was a problem hiding this comment.
My idea was that ArrayType is a Type. It with throw a "not implemented" exception for the SQL declaration (because we can't use it as a column type) but should be able to implement the rest of the methods.
There was a problem hiding this comment.
What would it do to convert a PHP value (an array, probably?) to a database value?
There was a problem hiding this comment.
It will delegate the conversion of each element of the array to its element type. We can start simple and accept only Type in the constructor to prove the idea:
public function __construct(private readonly Type $elementType)There was a problem hiding this comment.
When would it be necessary to use the ArrayType in this way?
There was a problem hiding this comment.
When building the query here. If this code builds the parameter types as [new ArrayType('rot13'), 'rot13'], the DBAL should be able to apply rot13 to the array elements similar to how it does with a single value.
|
After taking a closer look at this, I don't think Currently, we have two major type systems:
Also, we have Any attempt to define the expansion of an array of values to the |
Summary
The list of parameters conversion is currently limited to a few types expressed by the
ArrayParameterTypeenum.In doctrine/orm#11897, it might be necessary to express "list of parameters of a given custom type".
As suggested in doctrine/orm#11897 (comment), this PR is an initial exploration of using a new
ArrayTypeto be wrapped around any other underlying type.