1 | <?php |
||
36 | class Site |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * Cache for ApacheSolrForTypo3\Solr\Site objects |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected static $sitesCache = array(); |
||
45 | /** |
||
46 | * Small cache for the list of pages in a site, so that the results of this |
||
47 | * rather expensive operation can be used by all initializers without having |
||
48 | * each initializer do it again. |
||
49 | * |
||
50 | * TODO Move to caching framework once TYPO3 4.6 is the minimum required |
||
51 | * version. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected static $sitePagesCache = array(); |
||
56 | /** |
||
57 | * Root page record. |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $rootPage = array(); |
||
62 | /** |
||
63 | * The site's sys_language_mode |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $sysLanguageMode = null; |
||
68 | |||
69 | /** |
||
70 | * Constructor. |
||
71 | * |
||
72 | * @param int $rootPageId Site root page ID (uid). The page must be marked as site root ("Use as Root Page" flag). |
||
73 | */ |
||
74 | 54 | public function __construct($rootPageId) |
|
88 | |||
89 | /** |
||
90 | * Gets the Site for a specific page Id. |
||
91 | * |
||
92 | * @param int $pageId The page Id to get a Site object for. |
||
93 | * @return Site Site for the given page Id. |
||
94 | */ |
||
95 | 44 | public static function getSiteByPageId($pageId) |
|
96 | { |
||
97 | 44 | $rootPageId = Util::getRootPageId($pageId); |
|
98 | |||
99 | 44 | if (!isset(self::$sitesCache[$rootPageId])) { |
|
100 | 44 | self::$sitesCache[$rootPageId] = GeneralUtility::makeInstance(__CLASS__, |
|
101 | $rootPageId); |
||
102 | } |
||
103 | |||
104 | 44 | return self::$sitesCache[$rootPageId]; |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * Creates a dropdown selector of available TYPO3 sites with Solr |
||
109 | * configured. |
||
110 | * |
||
111 | * @param string $selectorName Name to be used in the select's name attribute |
||
112 | * @param Site $selectedSite Optional, currently selected site |
||
113 | * @return string Site selector HTML code |
||
114 | * @todo Extract into own class like indexing configuration selector |
||
115 | */ |
||
116 | public static function getAvailableSitesSelector( |
||
138 | |||
139 | /** |
||
140 | * Gets all available TYPO3 sites with Solr configured. |
||
141 | * |
||
142 | * @param bool $stopOnInvalidSite |
||
143 | * |
||
144 | * @return Site[] An array of available sites |
||
145 | */ |
||
146 | 14 | public static function getAvailableSites($stopOnInvalidSite = false) |
|
147 | { |
||
148 | 14 | $sites = array(); |
|
149 | |||
150 | 14 | $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry'); |
|
151 | 14 | $servers = $registry->get('tx_solr', 'servers', array()); |
|
152 | |||
153 | 14 | foreach ($servers as $server) { |
|
154 | 14 | if (isset($sites[$server['rootPageUid']])) { |
|
155 | //get each site only once |
||
156 | continue; |
||
157 | } |
||
158 | |||
159 | try { |
||
160 | 14 | $sites[$server['rootPageUid']] = GeneralUtility::makeInstance(__CLASS__, $server['rootPageUid']); |
|
161 | } catch (\InvalidArgumentException $e) { |
||
162 | if ($stopOnInvalidSite) { |
||
163 | 14 | throw $e; |
|
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | 14 | return $sites; |
|
169 | } |
||
170 | |||
171 | /** |
||
172 | * Returns the first available Site. |
||
173 | * |
||
174 | * @param bool $stopOnInvalidSite |
||
175 | * |
||
176 | * @return Site |
||
177 | */ |
||
178 | 13 | public static function getFirstAvailableSite($stopOnInvalidSite = false) |
|
183 | |||
184 | /** |
||
185 | * Clears the $sitePagesCache |
||
186 | * |
||
187 | */ |
||
188 | public static function clearSitePagesCache() |
||
192 | |||
193 | /** |
||
194 | * Gets the site's root page ID (uid). |
||
195 | * |
||
196 | * @return int The site's root page ID. |
||
197 | */ |
||
198 | public function getRootPageId() |
||
202 | 7 | ||
203 | 7 | /** |
|
204 | * Gets the site's label. The label is build from the the site title and root |
||
205 | 7 | * page ID (uid). |
|
206 | 7 | * |
|
207 | 7 | * @return string The site's label. |
|
208 | 7 | */ |
|
209 | public function getLabel() |
||
221 | |||
222 | /** |
||
223 | * Gets the site's Solr TypoScript configuration (plugin.tx_solr.*) |
||
224 | * |
||
225 | * @return \ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration The Solr TypoScript configuration |
||
226 | */ |
||
227 | public function getSolrConfiguration() |
||
231 | |||
232 | /** |
||
233 | * Gets the system languages (IDs) for which Solr connections have been |
||
234 | * configured. |
||
235 | * |
||
236 | * @return array Array of system language IDs for which connections have been configured on this site. |
||
237 | */ |
||
238 | public function getLanguages() |
||
256 | |||
257 | 1 | /** |
|
258 | * Gets the site's default language as configured in |
||
259 | 1 | * config.sys_language_uid. If sys_language_uid is not set, 0 is assumed to |
|
260 | 1 | * be the default. |
|
261 | 1 | * |
|
262 | 1 | * @return int The site's default language. |
|
263 | 1 | */ |
|
264 | public function getDefaultLanguage() |
||
281 | 5 | ||
282 | /** |
||
283 | 5 | * Generates a list of page IDs in this site. Attention, this includes |
|
284 | 5 | * all page types! Deleted pages are not included. |
|
285 | * |
||
286 | 5 | * @param int|string $rootPageId Page ID from where to start collection sub pages |
|
287 | 5 | * @param int $maxDepth Maximum depth to descend into the site tree |
|
288 | 5 | * @return array Array of pages (IDs) in this site |
|
289 | 5 | */ |
|
290 | 5 | public function getPages($rootPageId = 'SITE_ROOT', $maxDepth = 999) |
|
332 | |||
333 | 43 | /** |
|
334 | * Generates the site's unique Site Hash. |
||
335 | 43 | * |
|
336 | * The Site Hash is build from the site's main domain, the system encryption |
||
337 | * key, and the extension "tx_solr". These components are concatenated and |
||
338 | * sha1-hashed. |
||
339 | * |
||
340 | * @return string Site Hash. |
||
341 | */ |
||
342 | public function getSiteHash() |
||
346 | 44 | ||
347 | 44 | /** |
|
348 | * Gets the site's main domain. More specifically the first domain record in |
||
349 | 44 | * the site tree. |
|
350 | * |
||
351 | * @return string The site's main domain. |
||
352 | */ |
||
353 | public function getDomain() |
||
360 | |||
361 | /** |
||
362 | * Gets the site's root page. |
||
363 | * |
||
364 | * @return array The site's root page. |
||
365 | */ |
||
366 | public function getRootPage() |
||
370 | |||
371 | /** |
||
372 | * Gets the site's root page's title. |
||
373 | * |
||
374 | * @return string The site's root page's title |
||
375 | */ |
||
376 | public function getTitle() |
||
380 | 11 | ||
381 | 11 | /** |
|
382 | * Gets the site's config.sys_language_mode setting |
||
383 | * |
||
384 | 11 | * @return string The site's config.sys_language_mode |
|
385 | */ |
||
386 | public function getSysLanguageMode() |
||
395 | } |
||
396 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: