rector.php gets the codeQuality set: declare(strict_types=1) in the 85 files where Rector finds no call relying on scalar type juggling (mostly TCA and configuration, models, the content feed API and the import command), "or die" as "|| die", instanceof instead of null checks for object types, early returns and self:: in final classes. Hotel::setRooms() goes instead of getting the property Rector wanted to declare: nothing calls it, and there is no rooms column any more. Checked locally: cache warmup, the ep:* commands load, frontend crawl (~1,900 URLs) and the backchannel APIs render the same as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace EP\EpTheme\Middleware;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Server\MiddlewareInterface;
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
|
|
use TYPO3\CMS\Core\Site\SiteFinder;
|
|
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
|
|
|
|
/**
|
|
* Links to a form page carry the uid of the page they come from (?ref=123, e.g. the enquiry
|
|
* button of a product page). Its URL is kept in the session until AddReferrerFinisher puts it
|
|
* into the submission.
|
|
*/
|
|
class ReferrerMiddleware implements MiddlewareInterface
|
|
{
|
|
public const SESSION_KEY = 'referrer';
|
|
|
|
public function __construct(private readonly SiteFinder $siteFinder) {}
|
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
|
{
|
|
$ref = $request->getQueryParams()['ref'] ?? null;
|
|
$frontendUser = $request->getAttribute('frontend.user');
|
|
|
|
if (!is_numeric($ref) || !$frontendUser instanceof FrontendUserAuthentication) {
|
|
return $handler->handle($request);
|
|
}
|
|
|
|
try {
|
|
$url = (string)$this->siteFinder->getSiteByPageId((int)$ref)->getRouter()->generateUri((int)$ref);
|
|
$frontendUser->setKey('ses', self::SESSION_KEY, $url);
|
|
$frontendUser->storeSessionData();
|
|
} catch (SiteNotFoundException) {
|
|
}
|
|
|
|
return $handler->handle($request);
|
|
}
|
|
}
|