first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
namespace TYPO3\CMS\Frontend\Middleware;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use TYPO3\CMS\Core\Routing\SiteMatcher;
|
||||
use TYPO3\CMS\Core\Routing\SiteRouteResult;
|
||||
use TYPO3\CMS\Core\Site\SiteFinder;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Identifies if a site is configured for the request, based on "id" and "L" GET/POST parameters, or the requested
|
||||
* string.
|
||||
*
|
||||
* If a site is found, the request is populated with the found language+site objects. If none is found, the main magic
|
||||
* is handled by the PageResolver middleware.
|
||||
*/
|
||||
class SiteResolver implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* @var SiteMatcher
|
||||
*/
|
||||
protected $matcher;
|
||||
|
||||
public function __construct(SiteMatcher $matcher = null)
|
||||
{
|
||||
$this->matcher = $matcher ?? GeneralUtility::makeInstance(
|
||||
SiteMatcher::class,
|
||||
GeneralUtility::makeInstance(SiteFinder::class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the site/language information by checking the page ID or the URL.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
/** @var SiteRouteResult $routeResult */
|
||||
$routeResult = $this->matcher->matchRequest($request);
|
||||
$request = $request->withAttribute('site', $routeResult->getSite());
|
||||
$request = $request->withAttribute('language', $routeResult->getLanguage());
|
||||
$request = $request->withAttribute('routing', $routeResult);
|
||||
|
||||
// At this point, we later get further route modifiers
|
||||
// for bw-compat we update $GLOBALS[TYPO3_REQUEST] to be used later in TSFE.
|
||||
$GLOBALS['TYPO3_REQUEST'] = $request;
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user