Complex classes like Util often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Util, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 46 | class Util |
||
| 47 | { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Generates a document id for documents representing page records. |
||
| 51 | * |
||
| 52 | * @param int $uid The page's uid |
||
| 53 | * @param int $typeNum The page's typeNum |
||
| 54 | * @param int $language the language id, defaults to 0 |
||
| 55 | * @param string $accessGroups comma separated list of uids of groups that have access to that page |
||
| 56 | * @param string $mountPointParameter The mount point parameter that is used to access the page. |
||
| 57 | * @return string The document id for that page |
||
| 58 | */ |
||
| 59 | 42 | public static function getPageDocumentId( |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Generates a document id in the form $siteHash/$type/$uid. |
||
| 84 | * |
||
| 85 | * @param string $table The records table name |
||
| 86 | * @param int $pid The record's pid |
||
| 87 | * @param int $uid The record's uid |
||
| 88 | * @param string $additionalIdParameters Additional ID parameters |
||
| 89 | * @return string A document id |
||
| 90 | */ |
||
| 91 | 53 | public static function getDocumentId( |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Converts a date from unix timestamp to ISO 8601 format. |
||
| 109 | * |
||
| 110 | * @param int $timestamp unix timestamp |
||
| 111 | * @return string the date in ISO 8601 format |
||
| 112 | * @deprecated since 6.1 will be removed in 7.0 |
||
| 113 | */ |
||
| 114 | public static function timestampToIso($timestamp) |
||
| 115 | { |
||
| 116 | GeneralUtility::logDeprecatedFunction(); |
||
| 117 | $formatService = GeneralUtility::makeInstance(FormatService::class); |
||
| 118 | |||
| 119 | return $formatService->timestampToIso($timestamp); |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Converts a date from ISO 8601 format to unix timestamp. |
||
| 124 | * |
||
| 125 | * @param string $isoTime date in ISO 8601 format |
||
| 126 | * @return int unix timestamp |
||
| 127 | * @deprecated since 6.1 will be removed in 7.0 |
||
| 128 | */ |
||
| 129 | public static function isoToTimestamp($isoTime) |
||
| 130 | { |
||
| 131 | GeneralUtility::logDeprecatedFunction(); |
||
| 132 | $formatService = GeneralUtility::makeInstance(FormatService::class); |
||
| 133 | |||
| 134 | return $formatService->isoToTimestamp($isoTime); |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Converts a date from unix timestamp to ISO 8601 format in UTC timezone. |
||
| 139 | * |
||
| 140 | * @param int $timestamp unix timestamp |
||
| 141 | * @return string the date in ISO 8601 format |
||
| 142 | * @deprecated since 6.1 will be removed in 7.0 |
||
| 143 | */ |
||
| 144 | public static function timestampToUtcIso($timestamp) |
||
| 145 | { |
||
| 146 | GeneralUtility::logDeprecatedFunction(); |
||
| 147 | $formatService = GeneralUtility::makeInstance(FormatService::class); |
||
| 148 | |||
| 149 | return $formatService->timestampToUtcIso($timestamp); |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Converts a date from ISO 8601 format in UTC timezone to unix timestamp. |
||
| 154 | * |
||
| 155 | * @param string $isoTime date in ISO 8601 format |
||
| 156 | * @return int unix timestamp |
||
| 157 | * @deprecated since 6.1 will be removed in 7.0 |
||
| 158 | */ |
||
| 159 | public static function utcIsoToTimestamp($isoTime) |
||
| 160 | { |
||
| 161 | GeneralUtility::logDeprecatedFunction(); |
||
| 162 | $formatService = GeneralUtility::makeInstance(FormatService::class); |
||
| 163 | |||
| 164 | return $formatService->utcIsoToTimestamp($isoTime); |
||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Returns given word as CamelCased. |
||
| 169 | * |
||
| 170 | * Converts a word like "send_email" to "SendEmail". It |
||
| 171 | * will remove non alphanumeric characters from the word, so |
||
| 172 | * "who's online" will be converted to "WhoSOnline" |
||
| 173 | * |
||
| 174 | * @param string $word Word to convert to camel case |
||
| 175 | * @return string UpperCamelCasedWord |
||
| 176 | */ |
||
| 177 | public static function camelize($word) |
||
| 178 | { |
||
| 179 | return str_replace(' ', '', |
||
| 180 | ucwords(preg_replace('![^A-Z^a-z^0-9]+!', ' ', $word))); |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Returns a given CamelCasedString as an lowercase string with underscores. |
||
| 185 | * Example: Converts BlogExample to blog_example, and minimalValue to minimal_value |
||
| 186 | * |
||
| 187 | * @param string $string String to be converted to lowercase underscore |
||
| 188 | * @return string lowercase_and_underscored_string |
||
| 189 | */ |
||
| 190 | public static function camelCaseToLowerCaseUnderscored($string) |
||
| 191 | { |
||
| 192 | return strtolower(preg_replace('/(?<=\w)([A-Z])/', '_\\1', $string)); |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Returns a given string with underscores as UpperCamelCase. |
||
| 197 | * Example: Converts blog_example to BlogExample |
||
| 198 | * |
||
| 199 | * @param string $string String to be converted to camel case |
||
| 200 | * @return string UpperCamelCasedWord |
||
| 201 | */ |
||
| 202 | 26 | public static function underscoredToUpperCamelCase($string) |
|
| 203 | { |
||
| 204 | 26 | return str_replace(' ', '', |
|
| 205 | 26 | ucwords(str_replace('_', ' ', strtolower($string)))); |
|
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Shortcut to retrieve the TypoScript configuration for EXT:solr |
||
| 210 | * (plugin.tx_solr) from TSFE. |
||
| 211 | * |
||
| 212 | * @return TypoScriptConfiguration |
||
| 213 | */ |
||
| 214 | 148 | public static function getSolrConfiguration() |
|
| 215 | { |
||
| 216 | 148 | $configurationManager = self::getConfigurationManager(); |
|
| 217 | |||
| 218 | 148 | return $configurationManager->getTypoScriptConfiguration(); |
|
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return ConfigurationManager |
||
| 223 | */ |
||
| 224 | 184 | private static function getConfigurationManager() |
|
| 225 | { |
||
| 226 | /** @var ConfigurationManager $configurationManager */ |
||
| 227 | 184 | $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); |
|
| 228 | 184 | return $configurationManager; |
|
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Gets the Solr configuration for a specific root page id. |
||
| 233 | * To be used from the backend. |
||
| 234 | * |
||
| 235 | * @param int $pageId Id of the (root) page to get the Solr configuration from. |
||
| 236 | * @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE |
||
| 237 | * @param int $language System language uid, optional, defaults to 0 |
||
| 238 | * @return TypoScriptConfiguration The Solr configuration for the requested tree. |
||
| 239 | */ |
||
| 240 | 59 | public static function getSolrConfigurationFromPageId( |
|
| 241 | $pageId, |
||
| 242 | $initializeTsfe = false, |
||
| 243 | $language = 0 |
||
| 244 | ) { |
||
| 245 | 59 | $rootPath = ''; |
|
| 246 | 59 | return self::getConfigurationFromPageId($pageId, $rootPath, $initializeTsfe, $language); |
|
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Loads the TypoScript configuration for a given page id and language. |
||
| 251 | * Language usage may be disabled to get the default TypoScript |
||
| 252 | * configuration. |
||
| 253 | * |
||
| 254 | * @param int $pageId Id of the (root) page to get the Solr configuration from. |
||
| 255 | * @param string $path The TypoScript configuration path to retrieve. |
||
| 256 | * @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE |
||
| 257 | * @param int $language System language uid, optional, defaults to 0 |
||
| 258 | * @param bool $useTwoLevelCache Flag to enable the two level cache for the typoscript configuration array |
||
| 259 | * @return TypoScriptConfiguration The Solr configuration for the requested tree. |
||
| 260 | */ |
||
| 261 | 61 | public static function getConfigurationFromPageId( |
|
| 262 | $pageId, |
||
| 263 | $path, |
||
| 264 | $initializeTsfe = false, |
||
| 265 | $language = 0, |
||
| 266 | $useTwoLevelCache = true |
||
| 267 | ) { |
||
| 268 | 61 | static $configurationObjectCache = []; |
|
| 269 | 61 | $cacheId = md5($pageId . '|' . $path . '|' . $language); |
|
| 270 | 61 | if (isset($configurationObjectCache[$cacheId])) { |
|
| 271 | 53 | return $configurationObjectCache[$cacheId]; |
|
| 272 | } |
||
| 273 | |||
| 274 | // If we're on UID 0, we cannot retrieve a configuration currently. |
||
| 275 | // getRootline() below throws an exception (since #typo3-60 ) |
||
| 276 | // as UID 0 cannot have any parent rootline by design. |
||
| 277 | 61 | if ($pageId == 0) { |
|
| 278 | 2 | return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray([], $pageId, $language, $path); |
|
| 279 | } |
||
| 280 | |||
| 281 | 60 | if ($useTwoLevelCache) { |
|
| 282 | /** @var $cache TwoLevelCache */ |
||
| 283 | 60 | $cache = GeneralUtility::makeInstance(TwoLevelCache::class, 'tx_solr_configuration'); |
|
| 284 | 60 | $configurationArray = $cache->get($cacheId); |
|
| 285 | } |
||
| 286 | |||
| 287 | 60 | if (!empty($configurationArray)) { |
|
| 288 | // we have a cache hit and can return it. |
||
| 289 | return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path); |
||
| 290 | } |
||
| 291 | |||
| 292 | // we have nothing in the cache. We need to build the configurationToUse |
||
| 293 | 60 | $configurationArray = self::buildConfigurationArray($pageId, $path, $initializeTsfe, $language); |
|
| 294 | |||
| 295 | 60 | if ($useTwoLevelCache && isset($cache)) { |
|
| 296 | 60 | $cache->set($cacheId, $configurationArray); |
|
| 297 | } |
||
| 298 | |||
| 299 | 60 | return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path); |
|
| 300 | } |
||
| 301 | |||
| 302 | |||
| 303 | /** |
||
| 304 | * Initializes a TSFE, if required and builds an configuration array, containing the solr configuration. |
||
| 305 | * |
||
| 306 | * @param integer $pageId |
||
| 307 | * @param string $path |
||
| 308 | * @param boolean $initializeTsfe |
||
| 309 | * @param integer $language |
||
| 310 | * @return array |
||
| 311 | */ |
||
| 312 | 60 | protected static function buildConfigurationArray($pageId, $path, $initializeTsfe, $language) |
|
| 313 | { |
||
| 314 | 60 | if ($initializeTsfe) { |
|
| 315 | 2 | self::initializeTsfe($pageId, $language); |
|
| 316 | 2 | $configurationToUse = self::getConfigurationFromInitializedTSFE($path); |
|
| 317 | } else { |
||
| 318 | 60 | $configurationToUse = self::getConfigurationFromExistingTSFE($pageId, $path, $language); |
|
| 319 | } |
||
| 320 | |||
| 321 | 60 | return is_array($configurationToUse) ? $configurationToUse : []; |
|
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Builds the configuration object from a config array and returns it. |
||
| 326 | * |
||
| 327 | * @param array $configurationToUse |
||
| 328 | * @param int $pageId |
||
| 329 | * @param int $languageId |
||
| 330 | * @param string $typoScriptPath |
||
| 331 | * @return TypoScriptConfiguration |
||
| 332 | */ |
||
| 333 | 61 | protected static function buildTypoScriptConfigurationFromArray(array $configurationToUse, $pageId, $languageId, $typoScriptPath) |
|
| 334 | { |
||
| 335 | 61 | $configurationManager = self::getConfigurationManager(); |
|
| 336 | 61 | return $configurationManager->getTypoScriptConfiguration($configurationToUse, $pageId, $languageId, $typoScriptPath); |
|
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * This function is used to retrieve the configuration from a previous initialized TSFE |
||
| 341 | * (see: getConfigurationFromPageId) |
||
| 342 | * |
||
| 343 | * @param string $path |
||
| 344 | * @return mixed |
||
| 345 | */ |
||
| 346 | 2 | private static function getConfigurationFromInitializedTSFE($path) |
|
| 347 | { |
||
| 348 | /** @var $tmpl ExtendedTemplateService */ |
||
| 349 | 2 | $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class); |
|
| 350 | 2 | $configuration = $tmpl->ext_getSetup($GLOBALS['TSFE']->tmpl->setup, $path); |
|
| 351 | 2 | $configurationToUse = $configuration[0]; |
|
| 352 | 2 | return $configurationToUse; |
|
| 353 | } |
||
| 354 | |||
| 355 | /** |
||
| 356 | * This function is used to retrieve the configuration from an existing TSFE instance |
||
| 357 | * @param $pageId |
||
| 358 | * @param $path |
||
| 359 | * @param $language |
||
| 360 | * @return mixed |
||
| 361 | */ |
||
| 362 | 60 | private static function getConfigurationFromExistingTSFE($pageId, $path, $language) |
|
| 363 | { |
||
| 364 | 60 | if (is_int($language)) { |
|
| 365 | 60 | GeneralUtility::_GETset($language, 'L'); |
|
| 366 | } |
||
| 367 | |||
| 368 | /** @var $pageSelect PageRepository */ |
||
| 369 | 60 | $pageSelect = GeneralUtility::makeInstance(PageRepository::class); |
|
| 370 | 60 | $rootLine = $pageSelect->getRootLine($pageId); |
|
| 371 | |||
| 372 | 60 | $initializedTsfe = false; |
|
| 373 | 60 | $initializedPageSelect = false; |
|
| 374 | 60 | if (empty($GLOBALS['TSFE']->sys_page)) { |
|
| 375 | 51 | if (empty($GLOBALS['TSFE'])) { |
|
| 376 | 51 | $GLOBALS['TSFE'] = new \stdClass(); |
|
| 377 | 51 | $GLOBALS['TSFE']->tmpl = new \stdClass(); |
|
| 378 | 51 | $GLOBALS['TSFE']->tmpl->rootLine = $rootLine; |
|
| 379 | 51 | $GLOBALS['TSFE']->sys_page = $pageSelect; |
|
| 380 | 51 | $GLOBALS['TSFE']->id = $pageId; |
|
| 381 | 51 | $GLOBALS['TSFE']->tx_solr_initTsfe = 1; |
|
| 382 | 51 | $initializedTsfe = true; |
|
| 383 | } |
||
| 384 | |||
| 385 | 51 | $GLOBALS['TSFE']->sys_page = $pageSelect; |
|
| 386 | 51 | $initializedPageSelect = true; |
|
| 387 | } |
||
| 388 | /** @var $tmpl ExtendedTemplateService */ |
||
| 389 | 60 | $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class); |
|
| 390 | 60 | $tmpl->tt_track = false; // Do not log time-performance information |
|
| 391 | 60 | $tmpl->init(); |
|
| 392 | 60 | $tmpl->runThroughTemplates($rootLine); // This generates the constants/config + hierarchy info for the template. |
|
| 393 | 60 | $tmpl->generateConfig(); |
|
| 394 | |||
| 395 | 60 | $getConfigurationFromInitializedTSFEAndWriteToCache = $tmpl->ext_getSetup($tmpl->setup, $path); |
|
| 396 | 60 | $configurationToUse = $getConfigurationFromInitializedTSFEAndWriteToCache[0]; |
|
| 397 | |||
| 398 | 60 | if ($initializedPageSelect) { |
|
| 399 | 51 | $GLOBALS['TSFE']->sys_page = null; |
|
| 400 | } |
||
| 401 | 60 | if ($initializedTsfe) { |
|
| 402 | 51 | unset($GLOBALS['TSFE']); |
|
| 403 | } |
||
| 404 | 60 | return $configurationToUse; |
|
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Initializes the TSFE for a given page ID and language. |
||
| 409 | * |
||
| 410 | * @param int $pageId The page id to initialize the TSFE for |
||
| 411 | * @param int $language System language uid, optional, defaults to 0 |
||
| 412 | * @param bool $useCache Use cache to reuse TSFE |
||
| 413 | * @return void |
||
| 414 | */ |
||
| 415 | 15 | public static function initializeTsfe( |
|
| 416 | $pageId, |
||
| 417 | $language = 0, |
||
| 418 | $useCache = true |
||
| 419 | ) { |
||
| 420 | 15 | static $tsfeCache = []; |
|
| 421 | |||
| 422 | // resetting, a TSFE instance with data from a different page Id could be set already |
||
| 423 | 15 | unset($GLOBALS['TSFE']); |
|
| 424 | |||
| 425 | 15 | $cacheId = $pageId . '|' . $language; |
|
| 426 | |||
| 427 | 15 | if (!is_object($GLOBALS['TT'])) { |
|
| 428 | 15 | $GLOBALS['TT'] = GeneralUtility::makeInstance(NullTimeTracker::class); |
|
| 429 | } |
||
| 430 | |||
| 431 | 15 | if (!isset($tsfeCache[$cacheId]) || !$useCache) { |
|
| 432 | 15 | GeneralUtility::_GETset($language, 'L'); |
|
| 433 | |||
| 434 | 15 | $GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, |
|
| 435 | 15 | $GLOBALS['TYPO3_CONF_VARS'], $pageId, 0); |
|
| 436 | |||
| 437 | // for certain situations we need to trick TSFE into granting us |
||
| 438 | // access to the page in any case to make getPageAndRootline() work |
||
| 439 | // see http://forge.typo3.org/issues/42122 |
||
| 440 | 15 | $pageRecord = BackendUtility::getRecord('pages', $pageId, 'fe_group'); |
|
| 441 | 15 | $groupListBackup = $GLOBALS['TSFE']->gr_list; |
|
| 442 | 15 | $GLOBALS['TSFE']->gr_list = $pageRecord['fe_group']; |
|
| 443 | |||
| 444 | 15 | $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class); |
|
| 445 | 15 | $GLOBALS['TSFE']->getPageAndRootline(); |
|
| 446 | |||
| 447 | // restore gr_list |
||
| 448 | 15 | $GLOBALS['TSFE']->gr_list = $groupListBackup; |
|
| 449 | |||
| 450 | 15 | $GLOBALS['TSFE']->initTemplate(); |
|
| 451 | 15 | $GLOBALS['TSFE']->forceTemplateParsing = true; |
|
| 452 | 15 | $GLOBALS['TSFE']->initFEuser(); |
|
| 453 | 15 | $GLOBALS['TSFE']->initUserGroups(); |
|
| 454 | // $GLOBALS['TSFE']->getCompressedTCarray(); // seems to cause conflicts sometimes |
||
| 455 | |||
| 456 | 15 | $GLOBALS['TSFE']->no_cache = true; |
|
| 457 | 15 | $GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine); |
|
| 458 | 15 | $GLOBALS['TSFE']->no_cache = false; |
|
| 459 | 15 | $GLOBALS['TSFE']->getConfigArray(); |
|
| 460 | |||
| 461 | 15 | $GLOBALS['TSFE']->settingLanguage(); |
|
| 462 | 15 | if (!$useCache) { |
|
| 463 | $GLOBALS['TSFE']->settingLocale(); |
||
| 464 | } |
||
| 465 | |||
| 466 | 15 | $GLOBALS['TSFE']->newCObj(); |
|
| 467 | 15 | $GLOBALS['TSFE']->absRefPrefix = self::getAbsRefPrefixFromTSFE($GLOBALS['TSFE']); |
|
| 468 | 15 | $GLOBALS['TSFE']->calculateLinkVars(); |
|
| 469 | |||
| 470 | 15 | if ($useCache) { |
|
| 471 | 15 | $tsfeCache[$cacheId] = $GLOBALS['TSFE']; |
|
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | 15 | if ($useCache) { |
|
| 476 | 15 | $GLOBALS['TSFE'] = $tsfeCache[$cacheId]; |
|
| 477 | 15 | $GLOBALS['TSFE']->settingLocale(); |
|
| 478 | } |
||
| 479 | 15 | } |
|
| 480 | |||
| 481 | /** |
||
| 482 | * Determines the rootpage ID for a given page. |
||
| 483 | * |
||
| 484 | * @param int $pageId A page ID somewhere in a tree. |
||
| 485 | * @param bool $forceFallback Force the explicit detection and do not use the current frontend root line |
||
| 486 | * @return int The page's tree branch's root page ID |
||
| 487 | * @deprecated since 6.1 will be removed in 7.0 |
||
| 488 | */ |
||
| 489 | public static function getRootPageId($pageId = 0, $forceFallback = false) |
||
| 490 | { |
||
| 491 | GeneralUtility::logDeprecatedFunction(); |
||
| 492 | $rootPageResolver = GeneralUtility::makeInstance(RootPageResolver::class); |
||
| 493 | |||
| 494 | return $rootPageResolver->getRootPageId($pageId, $forceFallback); |
||
| 495 | } |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Takes a page Id and checks whether the page is marked as root page. |
||
| 499 | * |
||
| 500 | * @param int $pageId Page ID |
||
| 501 | * @return bool TRUE if the page is marked as root page, FALSE otherwise |
||
| 502 | * @deprecated since 6.1 will be removed in 7.0 |
||
| 503 | */ |
||
| 504 | public static function isRootPage($pageId) |
||
| 505 | { |
||
| 506 | GeneralUtility::logDeprecatedFunction(); |
||
| 507 | $rootPageResolver = GeneralUtility::makeInstance(RootPageResolver::class); |
||
| 508 | |||
| 509 | return $rootPageResolver->getIsRootPageId($pageId); |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Gets the site hash for a domain |
||
| 514 | * |
||
| 515 | * @deprecated since 6.1 will be removed in 7.0. use SiteHashService->getSiteHashForDomain now. |
||
| 516 | * @param string $domain Domain to calculate the site hash for. |
||
| 517 | * @return string site hash for $domain |
||
| 518 | */ |
||
| 519 | public static function getSiteHashForDomain($domain) |
||
| 520 | { |
||
| 521 | GeneralUtility::logDeprecatedFunction(); |
||
| 522 | /** @var $siteHashService SiteHashService */ |
||
| 523 | $siteHashService = GeneralUtility::makeInstance(SiteHashService::class); |
||
| 524 | return $siteHashService->getSiteHashForDomain($domain); |
||
| 525 | } |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Resolves magic keywords in allowed sites configuration. |
||
| 529 | * Supported keywords: |
||
| 530 | * __solr_current_site - The domain of the site the query has been started from |
||
| 531 | * __current_site - Same as __solr_current_site |
||
| 532 | * __all - Adds all domains as allowed sites |
||
| 533 | * * - Means all sites are allowed, same as no siteHash |
||
| 534 | * |
||
| 535 | * @deprecated since 6.1 will be removed in 7.0. use SiteHashService->getAllowedSitesForPageIdAndAllowedSitesConfiguration now. |
||
| 536 | * @param int $pageId A page ID that is then resolved to the site it belongs to |
||
| 537 | * @param string $allowedSitesConfiguration TypoScript setting for allowed sites |
||
| 538 | * @return string List of allowed sites/domains, magic keywords resolved |
||
| 539 | */ |
||
| 540 | public static function resolveSiteHashAllowedSites($pageId, $allowedSitesConfiguration) |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Check if record ($table, $uid) is a workspace record |
||
| 550 | * |
||
| 551 | * @param string $table The table the record belongs to |
||
| 552 | * @param int $uid The record's uid |
||
| 553 | * @return bool TRUE if the record is in a draft workspace, FALSE if it's a LIVE record |
||
| 554 | */ |
||
| 555 | 35 | public static function isDraftRecord($table, $uid) |
|
| 569 | |||
| 570 | /** |
||
| 571 | * Checks whether a record is a localization overlay. |
||
| 572 | * |
||
| 573 | * @param string $tableName The record's table name |
||
| 574 | * @param array $record The record to check |
||
| 575 | * @return bool TRUE if the record is a language overlay, FALSE otherwise |
||
| 576 | */ |
||
| 577 | 28 | public static function isLocalizedRecord($tableName, array $record) |
|
| 591 | |||
| 592 | /** |
||
| 593 | * Check if the page type of a page record is allowed |
||
| 594 | * |
||
| 595 | * @param array $pageRecord The pages database row |
||
| 596 | * @param string $configurationName The name of the configuration to use. |
||
| 597 | * |
||
| 598 | * @return bool TRUE if the page type is allowed, otherwise FALSE |
||
| 599 | */ |
||
| 600 | 27 | public static function isAllowedPageType(array $pageRecord, $configurationName = 'pages') |
|
| 612 | |||
| 613 | /** |
||
| 614 | * Get allowed page types |
||
| 615 | * |
||
| 616 | * @param int $pageId Page ID |
||
| 617 | * @param string $configurationName The name of the configuration to use. |
||
| 618 | * |
||
| 619 | * @return array Allowed page types to compare to a doktype of a page record |
||
| 620 | */ |
||
| 621 | 27 | public static function getAllowedPageTypes($pageId, $configurationName = 'pages') |
|
| 627 | |||
| 628 | /** |
||
| 629 | * Method to check if a page exists. |
||
| 630 | * |
||
| 631 | * @param int $pageId |
||
| 632 | * @return bool |
||
| 633 | */ |
||
| 634 | public static function pageExists($pageId) |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Resolves the configured absRefPrefix to a valid value and resolved if absRefPrefix |
||
| 647 | * is set to "auto". |
||
| 648 | * |
||
| 649 | * @param TypoScriptFrontendController $TSFE |
||
| 650 | * @return string |
||
| 651 | */ |
||
| 652 | 15 | public static function getAbsRefPrefixFromTSFE(TypoScriptFrontendController $TSFE) |
|
| 666 | |||
| 667 | /** |
||
| 668 | * This function can be used to check if one of the strings in needles is |
||
| 669 | * contained in the haystack. |
||
| 670 | * |
||
| 671 | * |
||
| 672 | * Example: |
||
| 673 | * |
||
| 674 | * haystack: the brown fox |
||
| 675 | * needles: ['hello', 'world'] |
||
| 676 | * result: false |
||
| 677 | * |
||
| 678 | * haystack: the brown fox |
||
| 679 | * needles: ['is', 'fox'] |
||
| 680 | * result: true |
||
| 681 | * |
||
| 682 | * @param string $haystack |
||
| 683 | * @param array $needles |
||
| 684 | * @return bool |
||
| 685 | */ |
||
| 686 | 33 | public static function containsOneOfTheStrings($haystack, array $needles) |
|
| 697 | } |
||
| 698 |