-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-5111: Introduced mapper registry for customizing value object bui…
…lding on search hits
- Loading branch information
1 parent
747765e
commit e011a31
Showing
18 changed files
with
442 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace Ibexa\Contracts\Core\Search\Subject; | ||
|
||
/** | ||
* Used to distinguish which implementation of Ibexa\Core\Repository\Mapper\SearchResultMapperInterface | ||
* should be responsible for mapping search results to ValueObjects. | ||
*/ | ||
interface SearchSubjectInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace Ibexa\Core\Repository\Mapper; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult; | ||
use Ibexa\Contracts\Core\Search\Subject\SearchSubjectInterface; | ||
|
||
interface SearchResultMapperInterface | ||
{ | ||
/** | ||
* @param array<mixed> $languageFilter | ||
* | ||
* @return array<\Ibexa\Contracts\Core\Persistence\ValueObject> | ||
*/ | ||
public function buildObjectsOnSearchResult(SearchResult $result, array $languageFilter = []): array; | ||
|
||
public function supports(SearchSubjectInterface $searchSubject): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace Ibexa\Core\Repository\Mapper; | ||
|
||
use Ibexa\Contracts\Core\Search\Subject\SearchSubjectInterface; | ||
use Ibexa\Core\Base\Exceptions\InvalidArgumentException; | ||
|
||
final class SearchResultMapperRegistry implements SearchResultMapperRegistryInterface | ||
{ | ||
/** @var iterable<\Ibexa\Core\Repository\Mapper\SearchResultMapperInterface> */ | ||
private iterable $mappers; | ||
|
||
/** | ||
* @param iterable<\Ibexa\Core\Repository\Mapper\SearchResultMapperInterface> $mappers | ||
*/ | ||
public function __construct(iterable $mappers) | ||
{ | ||
$this->mappers = $mappers; | ||
} | ||
|
||
public function hasMapper(SearchSubjectInterface $searchSubject): bool | ||
{ | ||
return $this->findMappers($searchSubject) !== null; | ||
} | ||
|
||
public function getMapper(SearchSubjectInterface $searchSubject): SearchResultMapperInterface | ||
{ | ||
$mapper = $this->findMappers($searchSubject); | ||
|
||
if ($mapper === null) { | ||
throw new InvalidArgumentException( | ||
'$hitValueObject', | ||
sprintf( | ||
'undefined %s for search subject %s', | ||
SearchResultMapperInterface::class, | ||
get_debug_type($searchSubject) | ||
) | ||
); | ||
} | ||
|
||
return $mapper; | ||
} | ||
|
||
private function findMappers(SearchSubjectInterface $searchSubject): ?SearchResultMapperInterface | ||
{ | ||
foreach ($this->mappers as $mapper) { | ||
if ($mapper->supports($searchSubject)) { | ||
return $mapper; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/lib/Repository/Mapper/SearchResultMapperRegistryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace Ibexa\Core\Repository\Mapper; | ||
|
||
use Ibexa\Contracts\Core\Search\Subject\SearchSubjectInterface; | ||
|
||
interface SearchResultMapperRegistryInterface | ||
{ | ||
public function hasMapper(SearchSubjectInterface $searchSubject): bool; | ||
|
||
public function getMapper(SearchSubjectInterface $searchSubject): SearchResultMapperInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.