1 | <?php |
||
25 | class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var EventDispatcherInterface |
||
29 | */ |
||
30 | protected $dispatcher; |
||
31 | |||
32 | /** |
||
33 | * Optional parameters. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $options = [ |
||
38 | 'identifier' => 'id', |
||
39 | 'index' => '', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * PropertyAccessor instance. |
||
44 | * |
||
45 | * @var PropertyAccessorInterface |
||
46 | */ |
||
47 | protected $propertyAccessor; |
||
48 | |||
49 | /** |
||
50 | * Instanciates a new Mapper. |
||
51 | */ |
||
52 | 38 | public function __construct(array $options = [], ?EventDispatcherInterface $dispatcher = null) |
|
57 | |||
58 | /** |
||
59 | * Set the PropertyAccessor. |
||
60 | */ |
||
61 | 38 | public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor) |
|
65 | |||
66 | /** |
||
67 | * Transforms an object into an elastica object having the required keys. |
||
68 | **/ |
||
69 | 26 | public function transform(object $object, array $fields): Document |
|
75 | |||
76 | /** |
||
77 | * transform a nested document or an object property into an array of ElasticaDocument. |
||
78 | * |
||
79 | * @param array|\Traversable|\ArrayAccess $objects the object to convert |
||
80 | * @param array $fields the keys we want to have in the returned array |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | 6 | protected function transformNested($objects, array $fields) |
|
102 | |||
103 | /** |
||
104 | * Attempts to convert any type to a string or an array of strings. |
||
105 | * |
||
106 | * @param mixed $value |
||
107 | * |
||
108 | * @return string|array |
||
109 | */ |
||
110 | 20 | protected function normalizeValue($value) |
|
111 | { |
||
112 | 20 | $normalizeValue = function (&$v) { |
|
113 | 20 | if ($v instanceof \DateTimeInterface) { |
|
114 | 2 | $v = $v->format('c'); |
|
115 | 20 | } elseif (!\is_scalar($v) && null !== $v) { |
|
116 | 1 | $v = (string) $v; |
|
117 | } |
||
118 | 20 | }; |
|
119 | |||
120 | 20 | if (\is_array($value) || $value instanceof \Traversable || $value instanceof \ArrayAccess) { |
|
121 | 6 | $value = \is_array($value) ? $value : \iterator_to_array($value, false); |
|
122 | 6 | \array_walk_recursive($value, $normalizeValue); |
|
123 | } else { |
||
124 | 16 | $normalizeValue($value); |
|
125 | } |
||
126 | |||
127 | 20 | return $value; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * Transforms the given object to an elastica document. |
||
132 | */ |
||
133 | 26 | protected function transformObjectToDocument(object $object, array $fields, string $identifier = ''): Document |
|
184 | } |
||
185 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: