|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace ApacheSolrForTypo3\Solr\System\Service; |
|
5
|
|
|
|
|
6
|
|
|
/* |
|
7
|
|
|
* This file is part of the TYPO3 CMS project. |
|
8
|
|
|
* |
|
9
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
10
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
11
|
|
|
* of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, please read the |
|
14
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
15
|
|
|
* |
|
16
|
|
|
* The TYPO3 project - inspiring people to share! |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Retrieves site related information. |
|
23
|
|
|
* |
|
24
|
|
|
* @todo When we have something like this available in TYPO39 and drop TYPO8 compatibility we can drop this class. |
|
25
|
|
|
*/ |
|
26
|
|
|
class SiteService implements SingletonInterface |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
/** @var array */ |
|
30
|
|
|
protected $sites = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Initialize domain configuration |
|
34
|
|
|
* @param array $sites |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(array $sites = []) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->sites = (count($sites) === 0) ? (array)$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['sites'] : $sites; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param int $rootPageId |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getFirstDomainForRootPage(int $rootPageId): string |
|
46
|
|
|
{ |
|
47
|
|
|
$siteByPageId = $this->getSiteForRootPageId($rootPageId); |
|
48
|
|
|
return $this->getFirstDomainFromSiteArray($siteByPageId); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Returns the configured domain from a site array or an empty string. |
|
53
|
|
|
* |
|
54
|
|
|
* @param array $site |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getFirstDomainFromSiteArray(array $site): string |
|
58
|
|
|
{ |
|
59
|
|
|
return (empty($site['domains'][0])) ? '' : $site['domains'][0]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Retrieves the configured site for a rootPageId. |
|
64
|
|
|
* |
|
65
|
|
|
* @param int $pageId |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getSiteForRootPageId(int $pageId): array |
|
69
|
|
|
{ |
|
70
|
|
|
return is_array($this->sites[$pageId]) ? $this->sites[$pageId] : []; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|