-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NGSTACK-843 move getSiteConfigForContent method to new service SiteAc…
…cessConfigResolver
- Loading branch information
Katarina Miočić
committed
May 9, 2024
1 parent
8849dbf
commit 890d577
Showing
5 changed files
with
74 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Netgen\IbexaSearchExtra\Core\Search\Common; | ||
|
||
use Ibexa\Contracts\Core\Persistence\Content\Handler as ContentHandler; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as LocationHandler; | ||
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; | ||
use RuntimeException; | ||
|
||
class SiteAccessConfigResolver | ||
{ | ||
|
||
/** | ||
* @param array<string, mixed> $sitesConfig | ||
*/ | ||
public function __construct( | ||
private readonly ContentHandler $contentHandler, | ||
private readonly LocationHandler $locationHandler, | ||
private readonly array $sitesConfig | ||
) { | ||
} | ||
|
||
public function getSiteConfigForContent(int $contentId): array | ||
{ | ||
$contentInfo = $this->contentHandler->loadContentInfo($contentId); | ||
|
||
try { | ||
$location = $this->locationHandler->load($contentInfo->mainLocationId); | ||
} catch (NotFoundException) { | ||
throw new RuntimeException( | ||
sprintf( | ||
'Content #%d does not have a location', | ||
$contentInfo->id, | ||
), | ||
); | ||
} | ||
|
||
$pathString = $location->pathString; | ||
$pathArray = explode('/', $pathString); | ||
|
||
foreach ($this->sitesConfig as $site => $siteConfig) { | ||
if (in_array($siteConfig['tree_root_location_id'], $pathArray, false)) { | ||
$siteConfig['site'] = $site; | ||
return $siteConfig; | ||
} | ||
} | ||
|
||
throw new RuntimeException( | ||
sprintf( | ||
"Failed to match content ID %d to a siteaccess", | ||
$contentInfo->id | ||
) | ||
); | ||
|
||
} | ||
} |
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