SiteMatcher.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Opentalent\OtOptimizer\Routing;
  3. use Opentalent\OtCore\Website\OtWebsiteRepository;
  4. use Psr\Http\Message\ServerRequestInterface;
  5. use TYPO3\CMS\Core\Routing\SiteRouteResult;
  6. use TYPO3\CMS\Core\Utility\GeneralUtility;
  7. use TYPO3\CMS\Extbase\Object\ObjectManager;
  8. /**
  9. * Hooks into the frontend request and use the ot_websites table to resolve the site configuration
  10. * (frontend only)
  11. *
  12. * @internal
  13. */
  14. class SiteMatcher extends \TYPO3\CMS\Core\Routing\SiteMatcher
  15. {
  16. /**
  17. * Override the default Typo3 \TYPO3\CMS\Core\Routing\SiteMatcher
  18. *
  19. * @param ServerRequestInterface $request
  20. * @return \TYPO3\CMS\Core\Routing\RouteResultInterface
  21. * @throws \Opentalent\OtCore\Exception\NoSuchWebsiteException
  22. */
  23. public function matchRequest(ServerRequestInterface $request): \TYPO3\CMS\Core\Routing\RouteResultInterface
  24. {
  25. $devMode = $_SERVER['TYPO3_CONTEXT'] == "Development";
  26. $otWebsiteRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
  27. $site = $otWebsiteRepository->matchUriToWebsite($request->getUri(), $devMode);
  28. if ($devMode) {
  29. preg_match("/\w+\/(.*)/", $request->getUri()->getPath(), $m);
  30. $tail = $m[1] ?? "";
  31. } else {
  32. $tail = $request->getUri()->getPath();
  33. }
  34. $language = $site->getDefaultLanguage();
  35. return new SiteRouteResult($request->getUri(), $site, $language, $tail);
  36. }
  37. }