1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the Aggregate document field value mapper class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\Search\Elasticsearch\Content\FieldValueMapper; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Search\Elasticsearch\Content\FieldValueMapper; |
14
|
|
|
use eZ\Publish\SPI\Search\Field; |
15
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotImplementedException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Maps raw document field values to something Elasticsearch can index. |
19
|
|
|
*/ |
20
|
|
|
class Aggregate extends FieldValueMapper |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Array of available mappers. |
24
|
|
|
* |
25
|
|
|
* @var \eZ\Publish\Core\Search\Elasticsearch\Content\FieldValueMapper[] |
26
|
|
|
*/ |
27
|
|
|
protected $mappers = array(); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Construct from optional mapper array. |
31
|
|
|
* |
32
|
|
|
* @param \eZ\Publish\Core\Search\Elasticsearch\Content\FieldValueMapper[] $mappers |
33
|
|
|
*/ |
34
|
|
|
public function __construct(array $mappers = array()) |
35
|
|
|
{ |
36
|
|
|
foreach ($mappers as $mapper) { |
37
|
|
|
$this->addMapper($mapper); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Adds mapper. |
43
|
|
|
* |
44
|
|
|
* @param \eZ\Publish\Core\Search\Elasticsearch\Content\FieldValueMapper $mapper |
45
|
|
|
*/ |
46
|
|
|
public function addMapper(FieldValueMapper $mapper) |
47
|
|
|
{ |
48
|
|
|
$this->mappers[] = $mapper; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Check if field can be mapped. |
53
|
|
|
* |
54
|
|
|
* @param \eZ\Publish\SPI\Search\Field $field |
55
|
|
|
* |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public function canMap(Field $field) |
59
|
|
|
{ |
60
|
|
|
return true; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Map field value to a proper Elasticsearch representation. |
65
|
|
|
* |
66
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotImplementedException |
67
|
|
|
* |
68
|
|
|
* @param \eZ\Publish\SPI\Search\Field $field |
69
|
|
|
* |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function map(Field $field) |
73
|
|
|
{ |
74
|
|
|
foreach ($this->mappers as $mapper) { |
75
|
|
|
if ($mapper->canMap($field)) { |
76
|
|
|
return $mapper->map($field); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
throw new NotImplementedException( |
81
|
|
|
'No mapper available for: ' . get_class($field->type) |
|
|
|
|
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.