lochmueller /
language_detection
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Lochmueller\LanguageDetection\Handler; |
||
| 6 | |||
| 7 | use Lochmueller\LanguageDetection\Check\EnableCheck; |
||
| 8 | use Lochmueller\LanguageDetection\Event\CheckLanguageDetectionEvent; |
||
| 9 | use Lochmueller\LanguageDetection\Event\DetectUserLanguagesEvent; |
||
| 10 | use Lochmueller\LanguageDetection\Event\NegotiateSiteLanguageEvent; |
||
| 11 | use Lochmueller\LanguageDetection\Handler\Exception\DisableLanguageDetectionException; |
||
|
0 ignored issues
–
show
|
|||
| 12 | use Lochmueller\LanguageDetection\Handler\Exception\NoSelectedLanguageException; |
||
|
0 ignored issues
–
show
The type
Lochmueller\LanguageDete...lectedLanguageException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 13 | use Lochmueller\LanguageDetection\Handler\Exception\NoUserLanguagesException; |
||
|
0 ignored issues
–
show
The type
Lochmueller\LanguageDete...oUserLanguagesException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | use Lochmueller\LanguageDetection\Service\SiteConfigurationService; |
||
| 15 | use Psr\Http\Message\ResponseInterface; |
||
| 16 | use Psr\Http\Message\ServerRequestInterface; |
||
| 17 | use Psr\Http\Server\RequestHandlerInterface; |
||
| 18 | use TYPO3\CMS\Core\Http\NullResponse; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Link handler for handling the language detection, with all 4 core events. |
||
| 22 | * But the response it not for redirect, it is a NullResponse. |
||
| 23 | * Please use the detected language uid in the header. |
||
| 24 | */ |
||
| 25 | class LinkLanguageHandler extends AbstractHandler implements RequestHandlerInterface |
||
|
0 ignored issues
–
show
The type
Lochmueller\LanguageDete...Handler\AbstractHandler was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 26 | { |
||
| 27 | public const HEADER_NAME = 'X-LANGUAGE-DETECTION-UID'; |
||
| 28 | |||
| 29 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 30 | { |
||
| 31 | $site = $this->getSiteFromRequest($request); |
||
| 32 | |||
| 33 | $check = new CheckLanguageDetectionEvent($site, $request); |
||
| 34 | $enableCheck = new EnableCheck(new SiteConfigurationService()); |
||
| 35 | $enableCheck($check); |
||
| 36 | |||
| 37 | if (!$check->isLanguageDetectionEnable()) { |
||
| 38 | throw new DisableLanguageDetectionException(); |
||
| 39 | } |
||
| 40 | |||
| 41 | $detect = new DetectUserLanguagesEvent($site, $request); |
||
| 42 | $this->eventDispatcher->dispatch($detect); |
||
| 43 | |||
| 44 | if ($detect->getUserLanguages()->isEmpty()) { |
||
| 45 | throw new NoUserLanguagesException(); |
||
| 46 | } |
||
| 47 | |||
| 48 | $negotiate = new NegotiateSiteLanguageEvent($site, $request, $detect->getUserLanguages()); |
||
| 49 | $this->eventDispatcher->dispatch($negotiate); |
||
| 50 | |||
| 51 | if ($negotiate->getSelectedLanguage() === null) { |
||
| 52 | throw new NoSelectedLanguageException(); |
||
| 53 | } |
||
| 54 | |||
| 55 | $response = new NullResponse(); |
||
| 56 | |||
| 57 | return $response->withAddedHeader(self::HEADER_NAME, (string)$negotiate->getSelectedLanguage()->getLanguageId()); |
||
| 58 | } |
||
| 59 | } |
||
| 60 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths