Skip to content

Commit 6d87ca3

Browse files
committed
Merge pull request #153 from phpcr/value-converter-multivalue
handle multivalue arrays in determineType
2 parents 17ddcfa + f0a9ecd commit 6d87ca3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/PHPCR/Util/ValueConverter.php

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class ValueConverter
3131
* - if the given $value is a Node object, type will be REFERENCE, unless
3232
* $weak is set to true which results in WEAKREFERENCE
3333
* - if the given $value is a DateTime object, the type will be DATE.
34+
* - if the $value is an empty array, the type is arbitrarily set to STRING
35+
* - if the $value is a non-empty array, the type of its first element is
36+
* chosen.
3437
*
3538
* Note that string is converted to date exactly if it matches the jcr
3639
* formatting spec for dates (sYYYY-MM-DDThh:mm:ss.sssTZD) according to
@@ -46,6 +49,15 @@ class ValueConverter
4649
*/
4750
public function determineType($value, $weak = false)
4851
{
52+
if (is_array($value)) {
53+
if (0 === count($value)) {
54+
// there is no value to determine the type on. we arbitrarily
55+
// chose string, which is what jackrabbit does as well.
56+
return PropertyType::STRING;
57+
}
58+
$value = reset($value);
59+
}
60+
4961
return PropertyType::determineType($value, $weak);
5062
}
5163

0 commit comments

Comments
 (0)