1 | <?php |
||
15 | class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var EventDispatcherInterface |
||
19 | */ |
||
20 | protected $dispatcher; |
||
21 | |||
22 | /** |
||
23 | * Optional parameters. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $options = array( |
||
28 | 'identifier' => 'id', |
||
29 | ); |
||
30 | |||
31 | /** |
||
32 | * PropertyAccessor instance. |
||
33 | * |
||
34 | * @var PropertyAccessorInterface |
||
35 | */ |
||
36 | protected $propertyAccessor; |
||
37 | |||
38 | /** |
||
39 | * Instanciates a new Mapper. |
||
40 | * |
||
41 | * @param array $options |
||
42 | * @param EventDispatcherInterface $dispatcher |
||
43 | */ |
||
44 | 35 | public function __construct(array $options = array(), EventDispatcherInterface $dispatcher = null) |
|
49 | |||
50 | /** |
||
51 | * Set the PropertyAccessor. |
||
52 | * |
||
53 | * @param PropertyAccessorInterface $propertyAccessor |
||
54 | */ |
||
55 | 35 | public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor) |
|
59 | |||
60 | /** |
||
61 | * Transforms an object into an elastica object having the required keys. |
||
62 | * |
||
63 | * @param object $object the object to convert |
||
64 | * @param array $fields the keys we want to have in the returned array |
||
65 | * |
||
66 | * @return Document |
||
67 | **/ |
||
68 | 24 | public function transform($object, array $fields) |
|
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 | 4 | 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 | protected function normalizeValue($value) |
||
129 | |||
130 | /** |
||
131 | * Transforms the given object to an elastica document |
||
132 | * |
||
133 | * @param object $object the object to convert |
||
134 | * @param array $fields the keys we want to have in the returned array |
||
135 | * @param string $identifier the identifier for the new document |
||
136 | * @return Document |
||
137 | */ |
||
138 | 24 | protected function transformObjectToDocument($object, array $fields, $identifier = '') |
|
194 | } |
||
195 |