meilisearch/Classes/Domain/Site/Typo3ManagedSite.php

100 lines
3.4 KiB
PHP
Raw Normal View History

2021-04-17 00:26:33 +02:00
<?php
namespace WapplerSystems\Meilisearch\Domain\Site;
/***************************************************************
* Copyright notice
*
* (c) 2019 Frans Saris <frans.saris@beech.it> & Timo Hund <timo.hund@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
2021-04-17 21:20:54 +02:00
use WapplerSystems\Meilisearch\NoMeilisearchConnectionFoundException;
2021-04-17 00:26:33 +02:00
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
use WapplerSystems\Meilisearch\System\Records\Pages\PagesRepository;
use TYPO3\CMS\Core\Context\LanguageAspectFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Site\Entity\Site as Typo3Site;
/**
* Class Typo3ManagedSite
*/
class Typo3ManagedSite extends Site
{
/**
* @var Typo3Site
*/
protected $typo3SiteObject;
/**
* @var array
*/
2021-04-24 04:44:44 +02:00
protected $meilisearchConnectionConfiguration;
2021-04-17 00:26:33 +02:00
public function __construct(
2021-04-29 18:33:05 +02:00
$site,
2021-04-17 00:26:33 +02:00
TypoScriptConfiguration $configuration,
2021-04-24 04:44:44 +02:00
array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, array $meilisearchConnectionConfiguration = [], Typo3Site $typo3SiteObject = null)
2021-04-17 00:26:33 +02:00
{
2021-04-29 18:33:05 +02:00
$this->site = $site;
2021-04-17 00:26:33 +02:00
$this->configuration = $configuration;
$this->rootPage = $page;
$this->domain = $domain;
$this->siteHash = $siteHash;
$this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class);
2021-04-24 04:44:44 +02:00
$this->meilisearchConnectionConfiguration = $meilisearchConnectionConfiguration;
2021-04-17 00:26:33 +02:00
$this->typo3SiteObject = $typo3SiteObject;
}
/**
* @return array
2021-04-17 21:20:54 +02:00
* @throws NoMeilisearchConnectionFoundException
2021-04-17 00:26:33 +02:00
*/
2021-04-24 04:44:44 +02:00
public function getMeilisearchConnectionConfiguration(): array
2021-04-17 00:26:33 +02:00
{
2021-04-24 04:44:44 +02:00
if (!is_array($this->meilisearchConnectionConfiguration)) {
2021-04-17 21:20:54 +02:00
/* @var $noMeilisearchConnectionException NoMeilisearchConnectionFoundException */
$noMeilisearchConnectionException = GeneralUtility::makeInstance(
NoMeilisearchConnectionFoundException::class,
/** @scrutinizer ignore-type */ 'Could not find a Meilisearch connection for root page [' . $this->getRootPageId() . '] and language [' . $language . '].',
2021-04-17 00:26:33 +02:00
/** @scrutinizer ignore-type */ 1552491117
);
2021-04-17 21:20:54 +02:00
$noMeilisearchConnectionException->setRootPageId($this->getRootPageId());
2021-04-17 00:26:33 +02:00
2021-04-17 21:20:54 +02:00
throw $noMeilisearchConnectionException;
2021-04-17 00:26:33 +02:00
}
2021-04-24 04:44:44 +02:00
return $this->meilisearchConnectionConfiguration;
2021-04-17 00:26:33 +02:00
}
/**
* Returns \TYPO3\CMS\Core\Site\Entity\Site
*
* @return Typo3Site
*/
public function getTypo3SiteObject(): Typo3Site
{
return $this->typo3SiteObject;
}
2021-04-24 04:44:44 +02:00
2021-04-17 00:26:33 +02:00
}