| @@ 17-59 (lines=43) @@ | ||
| 14 | /** |
|
| 15 | * todo |
|
| 16 | */ |
|
| 17 | class Aggregate extends PermissionInfoMapper |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * @var \eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper[] |
|
| 21 | */ |
|
| 22 | private $mappers; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param \eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper[] $mappers |
|
| 26 | */ |
|
| 27 | public function __construct(array $mappers = []) |
|
| 28 | { |
|
| 29 | foreach ($mappers as $mapper) { |
|
| 30 | $this->addMapper($mapper); |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @param \eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper $mapper |
|
| 36 | */ |
|
| 37 | public function addMapper(PermissionInfoMapper $mapper) |
|
| 38 | { |
|
| 39 | $this->mappers[] = $mapper; |
|
| 40 | } |
|
| 41 | ||
| 42 | public function canMap(ValueObject $object) |
|
| 43 | { |
|
| 44 | return true; |
|
| 45 | } |
|
| 46 | ||
| 47 | public function map(ValueObject $object, UserReference $userReference) |
|
| 48 | { |
|
| 49 | foreach ($this->mappers as $mapper) { |
|
| 50 | if ($mapper->canMap($object)) { |
|
| 51 | return $mapper->map($object, $userReference); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| 55 | throw new NotImplementedException( |
|
| 56 | 'No mapper available for: ' . get_class($object) |
|
| 57 | ); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 20-84 (lines=65) @@ | ||
| 17 | /** |
|
| 18 | * Common aggregate mapper implementation. |
|
| 19 | */ |
|
| 20 | class Aggregate extends FieldValueMapper |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * Array of available mappers. |
|
| 24 | * |
|
| 25 | * @var \eZ\Publish\Core\Search\Common\FieldValueMapper[] |
|
| 26 | */ |
|
| 27 | protected $mappers = array(); |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Construct from optional mapper array. |
|
| 31 | * |
|
| 32 | * @param \eZ\Publish\Core\Search\Common\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\Common\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 search engine 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 | ||