From e9faf29790a6fd9d2eead918eb2a122bc42bfd11 Mon Sep 17 00:00:00 2001 From: kranz Date: Mon, 28 Mar 2022 17:28:09 +0200 Subject: [PATCH 01/10] [TASK] Initial commit for TYPO3 11 development branch --- composer.json | 4 ++-- ext_emconf.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 73038b4..2ae1d69 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,8 @@ } ], "require": { - "typo3/cms-core": "^10.4.10 || ^11.0.0", - "typo3/cms-frontend": "^10.4.10 || ^11.0.0", + "typo3/cms-core": "^10.4.10 || ^11.5.0", + "typo3/cms-frontend": "^10.4.10 || ^11.5.0", "symfony/console": "^4.4 || ^5.0" }, "suggest": { diff --git a/ext_emconf.php b/ext_emconf.php index 680f4e7..7baca0c 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -7,7 +7,7 @@ 'category' => 'fe', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.0-11.0.99', + 'typo3' => '10.4.0-11.5.99', ], 'conflicts' => [], 'suggests' => [ From 008e24ef9a4c4744f61ba9487dccd82d5c46eecb Mon Sep 17 00:00:00 2001 From: kranz Date: Wed, 30 Mar 2022 17:56:00 +0200 Subject: [PATCH 02/10] [WIP] Deprecated functions replaced, minor code style changes, README changes --- Classes/Command/UpdateIpDatabaseCommand.php | 5 ++++- Classes/Domain/Repository/RegionRepository.php | 4 ++-- Classes/FactProvider/IP2Country.php | 2 +- Classes/Hook/OverrideIconOverlayHook.php | 2 +- Classes/Judge/Condition.php | 6 ++++++ Classes/Utility/LocateUtility.php | 11 ++++++----- README.md | 18 +++++++++--------- composer.json | 12 +++++++++--- 8 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Classes/Command/UpdateIpDatabaseCommand.php b/Classes/Command/UpdateIpDatabaseCommand.php index 28f1571..819d11a 100644 --- a/Classes/Command/UpdateIpDatabaseCommand.php +++ b/Classes/Command/UpdateIpDatabaseCommand.php @@ -103,7 +103,10 @@ private function validateArguments(): bool private function truncateTable(): void { $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->table); - $connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSQL($this->table, true)); + $databasePlatform = $connection->getDatabasePlatform(); + if ($databasePlatform) { + $connection->executeStatement($databasePlatform->getTruncateTableSQL($this->table, true)); + } } /** diff --git a/Classes/Domain/Repository/RegionRepository.php b/Classes/Domain/Repository/RegionRepository.php index 3701e93..fc66495 100644 --- a/Classes/Domain/Repository/RegionRepository.php +++ b/Classes/Domain/Repository/RegionRepository.php @@ -33,7 +33,7 @@ public function getCountriesForPage(int $id): array ->join('rmm', 'static_countries', 'c', 'c.uid = rmm.uid_foreign') ->where($qb->expr()->eq('pmm.uid_local', $qb->createNamedParameter($id, \PDO::PARAM_INT))) ->execute() - ->fetchAll(); + ->fetchAllAssociative(); foreach ($results as $result) { $iso2Codes[$result['cn_iso_2']] = true; @@ -52,7 +52,7 @@ public function shouldApplyWhenNoIpMatches(int $id): bool ->where($qb->expr()->eq('uid_local', $qb->createNamedParameter($id, \PDO::PARAM_INT))) ->andWhere($qb->expr()->eq('uid_foreign', $qb->createNamedParameter(self::APPLY_WHEN_NO_IP_MATCHES, \PDO::PARAM_INT))) ->execute() - ->fetchAll(); + ->fetchAllAssociative(); return !empty($results); } diff --git a/Classes/FactProvider/IP2Country.php b/Classes/FactProvider/IP2Country.php index eab36de..4245010 100644 --- a/Classes/FactProvider/IP2Country.php +++ b/Classes/FactProvider/IP2Country.php @@ -33,7 +33,7 @@ public function getBasename(): string */ public function process(): self { - $iso2 = GeneralUtility::makeInstance(LocateUtility::class)->getCountryIso2FromIP(); + $iso2 = GeneralUtility::makeInstance(LocateUtility::class)->getCountryIso2FromIP() ?? ''; LocateUtility::mainstreamValue($iso2); $this->facts[$this->getBasename()] = $iso2; diff --git a/Classes/Hook/OverrideIconOverlayHook.php b/Classes/Hook/OverrideIconOverlayHook.php index 10ad9ae..efb132e 100644 --- a/Classes/Hook/OverrideIconOverlayHook.php +++ b/Classes/Hook/OverrideIconOverlayHook.php @@ -52,6 +52,6 @@ private function countRegions(string $table, array $row): int ->from($table) ->where($qb->expr()->eq('uid', $row['uid'])) ->execute() - ->fetchColumn(0); + ->fetchOne(); } } diff --git a/Classes/Judge/Condition.php b/Classes/Judge/Condition.php index fc88bc9..c54d7d1 100644 --- a/Classes/Judge/Condition.php +++ b/Classes/Judge/Condition.php @@ -14,6 +14,7 @@ namespace Leuchtfeuer\Locate\Judge; use Leuchtfeuer\Locate\FactProvider\AbstractFactProvider; +use TYPO3\CMS\Extbase\Utility\DebuggerUtility; class Condition extends AbstractJudge { @@ -24,6 +25,11 @@ public function adjudicate(AbstractFactProvider $factProvider, int $priority = A { $prosecution = $this->configuration['prosecution'] ?? $this->configuration['prosecution.'] ?? null; + DebuggerUtility::var_dump($prosecution); + DebuggerUtility::var_dump($factProvider); + DebuggerUtility::var_dump($priority); + die; + if ($prosecution !== null && $factProvider->isGuilty($prosecution) && isset($this->configuration['verdict'])) { $this->decision = (new Decision())->withVerdictName($this->configuration['verdict']); $this->decision->setPriority($priority); diff --git a/Classes/Utility/LocateUtility.php b/Classes/Utility/LocateUtility.php index 0132519..97c71f7 100644 --- a/Classes/Utility/LocateUtility.php +++ b/Classes/Utility/LocateUtility.php @@ -27,7 +27,7 @@ class LocateUtility public function getCountryIso2FromIP(?string $ip = null) { $ip = $this->getNumericIp($ip); - $tableName = self::getTableNameForIp($ip); + $tableName = $this->getTableNameForIp($ip); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName); return $queryBuilder @@ -36,12 +36,12 @@ public function getCountryIso2FromIP(?string $ip = null) ->where($queryBuilder->expr()->lte('ip_from', $queryBuilder->createNamedParameter($ip))) ->andWhere($queryBuilder->expr()->gte('ip_to', $queryBuilder->createNamedParameter($ip))) ->execute() - ->fetchColumn(0); + ->fetchOne(); } public function getNumericIp(?string $ip = null): string { - $ip = $ip ?? GeneralUtility::getIndpEnv('REMOTE_ADDR'); + $ip = $ip ?? (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'); return strpos($ip, '.') !== false ? (string)ip2long($ip) : $this->convertIpv6($ip); } @@ -63,7 +63,8 @@ private function convertIpv6(string $ip): string break; case function_exists('bcadd'): - for ($i = 0; $i < strlen($bin); $i++) { + $max = strlen($bin); + for ($i = 0; $i < $max; $i++) { $decimalIp = bcmul($decimalIp, '2'); $decimalIp = bcadd($decimalIp, $bin[$i]); } @@ -80,7 +81,7 @@ private function convertIpv6(string $ip): string return $decimalIp; } - public static function mainstreamValue(string &$value) + public static function mainstreamValue(string &$value): void { $value = mb_strtolower(str_replace('-', '_', $value)); } diff --git a/README.md b/README.md index 2c43789..44ca07c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ Language Utilities for TYPO3 ============================ +[![TYPO3 10](https://img.shields.io/badge/TYPO3-10-orange.svg)](https://get.typo3.org/version/10) +[![TYPO3 11](https://img.shields.io/badge/TYPO3-11-orange.svg)](https://get.typo3.org/version/11) [![Latest Stable Version](https://poser.pugx.org/leuchtfeuer/locate/v/stable)](https://packagist.org/packages/leuchtfeuer/locate) [![Build Status](https://github.com/Leuchtfeuer/locate/workflows/Continous%20Integration/badge.svg)](https://github.com/Leuchtfeuer/locate/actions) [![Total Downloads](https://poser.pugx.org/leuchtfeuer/locate/downloads)](https://packagist.org/leuchtfeuer/locate) -[![Latest Unstable Version](https://poser.pugx.org/leuchtfeuer/locate/v/unstable)](https://packagist.org/leuchtfeuer/locate) [![Code Climate](https://codeclimate.com/github/Leuchtfeuer/locate/badges/gpa.svg)](https://codeclimate.com/github/Leuchtfeuer/locate) [![codecov](https://codecov.io/gh/Leuchtfeuer/locate/branch/master/graph/badge.svg?token=0GcE422Ms1)](https://codecov.io/gh/Leuchtfeuer/locate) [![License](https://poser.pugx.org/leuchtfeuer/locate/license)](https://packagist.org/packages/leuchtfeuer/locate) @@ -18,14 +19,13 @@ The full documentation for the latest releases can be found [here](https://docs. We are currently supporting following TYPO3 versions:

-| Extension Version | TYPO3 v10 Support | TYPO3 v9 Support | TYPO3 v8 Support | -| :-: | :-: | :-: | :-: | -| 11.x | x | - | - | -| 10.x | x | x | - | -| 9.x | - | x | - | -| 8.x | - | x | x | - -_Beta support for TYPO3 v11.0 is available since version 11.0.0._ +| Extension Version | TYPO3 v11 Support | TYPO3 v10 Support | TYPO3 v9 Support | TYPO3 v8 Support | +|-------------------|-------------------|-------------------|------------------|------------------| +| 11.x | x | x | - | - | +| 10.x | - | x | x | - | +| 9.x | - | x | - | - | +| 8.x | - | x | x | - | +| 7.x | - | - | - | 8 | ### IPv6 Support diff --git a/composer.json b/composer.json index 2ae1d69..c3f2c6e 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,10 @@ } ], "require": { - "typo3/cms-core": "^10.4.10 || ^11.5.0", - "typo3/cms-frontend": "^10.4.10 || ^11.5.0", + "typo3/cms-backend": "^10.4 || ^11.5", + "typo3/cms-core": "^10.4 || ^11.5", + "typo3/cms-extbase": "^10.4 || ^11.5", + "typo3/cms-frontend": "^10.4 || ^11.5", "symfony/console": "^4.4 || ^5.0" }, "suggest": { @@ -53,7 +55,11 @@ }, "config": { "vendor-dir": ".Build/vendor", - "bin-dir": ".Build/bin" + "bin-dir": ".Build/bin", + "allow-plugins": { + "typo3/class-alias-loader": true, + "typo3/cms-composer-installers": true + } }, "scripts": { "post-autoload-dump": [ From 6465cd851bc796be4ce4b84aca81cd4f61f1dcc7 Mon Sep 17 00:00:00 2001 From: kranz Date: Sun, 10 Apr 2022 16:28:30 +0200 Subject: [PATCH 03/10] [WIP] Change "cookie" namings to "session" --- .gitignore | 2 + Classes/Judge/Condition.php | 6 --- Classes/Processor/Court.php | 3 +- Classes/Verdict/Redirect.php | 78 ++++++++++++++++++------------------ 4 files changed, 42 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 485dee6..296ade8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .idea +.Build +composer.lock \ No newline at end of file diff --git a/Classes/Judge/Condition.php b/Classes/Judge/Condition.php index c54d7d1..fc88bc9 100644 --- a/Classes/Judge/Condition.php +++ b/Classes/Judge/Condition.php @@ -14,7 +14,6 @@ namespace Leuchtfeuer\Locate\Judge; use Leuchtfeuer\Locate\FactProvider\AbstractFactProvider; -use TYPO3\CMS\Extbase\Utility\DebuggerUtility; class Condition extends AbstractJudge { @@ -25,11 +24,6 @@ public function adjudicate(AbstractFactProvider $factProvider, int $priority = A { $prosecution = $this->configuration['prosecution'] ?? $this->configuration['prosecution.'] ?? null; - DebuggerUtility::var_dump($prosecution); - DebuggerUtility::var_dump($factProvider); - DebuggerUtility::var_dump($priority); - die; - if ($prosecution !== null && $factProvider->isGuilty($prosecution) && isset($this->configuration['verdict'])) { $this->decision = (new Decision())->withVerdictName($this->configuration['verdict']); $this->decision->setPriority($priority); diff --git a/Classes/Processor/Court.php b/Classes/Processor/Court.php index d9be1c9..bcd9fc6 100644 --- a/Classes/Processor/Court.php +++ b/Classes/Processor/Court.php @@ -141,8 +141,7 @@ protected function callJudges(): ?Decision $configuration = $this->configuration['judges'][$key . '.'] ?? []; if (empty($configuration)) { - $this->logger->warning(''); - // TODO: Do something? + $this->logger->warning('No judges are configured.'); } $this->logger->info(sprintf('Judge with key "%s" will be called.', $key)); diff --git a/Classes/Verdict/Redirect.php b/Classes/Verdict/Redirect.php index 323efb6..d79f8fe 100644 --- a/Classes/Verdict/Redirect.php +++ b/Classes/Verdict/Redirect.php @@ -28,7 +28,7 @@ class Redirect extends AbstractVerdict const SESSION_KEY = 'language'; const OVERRIDE_PARAMETER = 'setLang'; - private $cookieMode = false; + private $sessionMode = false; private $redirectLanguageUid = 0; @@ -43,9 +43,9 @@ public function execute(): ?ResponseInterface $this->redirectLanguageUid = (int)$this->configuration['sys_language']; $this->requestedLanguageUid = GeneralUtility::makeInstance(Context::class)->getAspect('language')->getId(); - // Initialize Cookie mode if necessary and prepare everything for possible redirects - $this->initializeCookieMode(); - $this->handleCookieStuff(); + // Initialize Session mode if necessary and prepare everything for possible redirects + $this->initializeSessionMode(); + $this->handleSessionStuff(); // Skip if no redirect is necessary if (!$this->shouldRedirect()) { @@ -66,60 +66,60 @@ public function execute(): ?ResponseInterface } /** - * Set CookeMode Param to true if sessionHandling is enables + * Set sessionMode Param to true if sessionHandling is enables */ - private function initializeCookieMode(): void + private function initializeSessionMode(): void { if ((bool)($this->configuration['sessionHandling'] ?? false) === true) { - $this->logger->info('Cookie Handling is set.'); - $this->cookieMode = true; + $this->logger->info('Session Handling is set.'); + $this->sessionMode = true; } } - private function handleCookieStuff() + private function handleSessionStuff() { $currentLanguageUid = $this->requestedLanguageUid; - if ($this->isCookieSet()) { - // Cookie is not in current language - $this->logger->info('Cookie is set.'); + if ($this->isSessionValueSet()) { + // Session is not in current language + $this->logger->info('Session value is set.'); - if ($this->isCookieInCurrentLanguage() === false && $this->shouldOverrideSessionValue() === true) { - // Override cookie - $this->logger->info('Cookie is not in current language, so we override it.'); + if ($this->isSessionInCurrentLanguage() === false && $this->shouldOverrideSessionValue() === true) { + // Override session + $this->logger->info('Session is not in current language, so we override it.'); $this->redirectLanguageUid = $currentLanguageUid; - $this->setCookie($currentLanguageUid); - } elseif ($this->isCookieInCurrentLanguage()) { - // Cookie is in current language - $this->logger->info('Cookie is in current language.'); + $this->setSessionValue($currentLanguageUid); + } elseif ($this->isSessionInCurrentLanguage()) { + // Session is in current language + $this->logger->info('Session is in current language.'); $this->redirectLanguageUid = $currentLanguageUid; } else { - // Override config array by cookie value - $this->logger->info('Cookie is not in current language and overriding is not allowed.'); - $this->redirectLanguageUid = $this->getCookieValue(); - $this->configuration['sys_language'] = $this->getCookieValue(); + // Override config array by session value + $this->logger->info('Session is not in current language and overriding is not allowed.'); + $this->redirectLanguageUid = $this->getSessionValue(); + $this->configuration['sys_language'] = $this->getSessionValue(); } - } elseif ($this->cookieMode === true) { - $this->logger->info('Cookie is not set, but we are in cookie mode.'); + } elseif ($this->sessionMode === true) { + $this->logger->info('Session is not set, but we are in session mode.'); if ($currentLanguageUid !== $this->redirectLanguageUid) { - // Set cookie value to target language - $this->setCookie($this->redirectLanguageUid); + // Set session value to target language + $this->setSessionValue($this->redirectLanguageUid); } else { - // Set cookie value to current language - $this->setCookie($currentLanguageUid); + // Set session value to current language + $this->setSessionValue($currentLanguageUid); } } } - private function isCookieSet(): bool + private function isSessionValueSet(): bool { - return $this->getCookieValue() !== null; + return $this->getSessionValue() !== null; } - private function isCookieInCurrentLanguage(): bool + private function isSessionInCurrentLanguage(): bool { - return $this->requestedLanguageUid === $this->getCookieValue(); + return $this->requestedLanguageUid === $this->getSessionValue(); } private function shouldOverrideSessionValue(): bool @@ -131,7 +131,7 @@ private function shouldOverrideSessionValue(): bool return false; } - private function setCookie(?int $value) + private function setSessionValue(?int $value) { if ($value === null) { $value = (int)$this->configuration['sys_language']; @@ -140,15 +140,15 @@ private function setCookie(?int $value) $this->session->set(self::SESSION_KEY, $value); } - private function getCookieValue(): ?int + private function getSessionValue(): ?int { return $this->session->get(self::SESSION_KEY); } private function shouldRedirect(): bool { - // Always redirect when we are not in cookie mode - if ($this->cookieMode === false) { + // Always redirect when we are not in session mode + if ($this->sessionMode === false) { return true; } @@ -162,8 +162,8 @@ private function shouldRedirect(): bool } } - // Do not redirect, when cookie is set and cookie value matches given language id - if ($this->isCookieInCurrentLanguage()) { + // Do not redirect, when session is set and session value matches given language id + if ($this->isSessionInCurrentLanguage()) { return false; } From 30f830aff97520dc1ce07053ae3bb4d5aa44a073 Mon Sep 17 00:00:00 2001 From: kranz Date: Sun, 10 Apr 2022 21:48:32 +0200 Subject: [PATCH 04/10] [TASK] Add option to simulate IP address for test purposes, bugfix for multiple IP judges --- Classes/FactProvider/AbstractFactProvider.php | 16 +++------------- Classes/FactProvider/BrowserAcceptedLanguage.php | 4 ++-- Classes/FactProvider/IP2Country.php | 6 ++++-- Classes/Judge/Condition.php | 2 +- .../Middleware/LanguageRedirectMiddleware.php | 1 + Classes/Processor/Court.php | 2 +- ...tch_language.txt => example_setup.typoscript} | 3 +++ Configuration/TypoScript/setup.typoscript | 7 +++++-- 8 files changed, 20 insertions(+), 21 deletions(-) rename Configuration/TypoScript/{setup-switch_language.txt => example_setup.typoscript} (94%) diff --git a/Classes/FactProvider/AbstractFactProvider.php b/Classes/FactProvider/AbstractFactProvider.php index 7ba3e3a..b8128c3 100644 --- a/Classes/FactProvider/AbstractFactProvider.php +++ b/Classes/FactProvider/AbstractFactProvider.php @@ -27,10 +27,12 @@ abstract class AbstractFactProvider /** * @param string $basename The basename for the factsArray. This name comes from configuration. + * @param array $configuration TypoScript configuration array for this fact provider */ - public function __construct(string $basename = '') + public function __construct(string $basename = '', array $configuration = []) { $this->basename = $basename; + $this->configuration = $configuration; } public function isMultiple(): bool @@ -65,18 +67,6 @@ protected function getFactPropertyName(string $property): string return mb_strtolower($property); } - /** - * @return array|mixed - */ - public function getSubject() - { - if (count($this->facts) > 1) { - return $this->facts; - } - - return array_shift($this->facts); - } - /** * Priority is only set if there are multiple facts (e.g. for browser accept languages) */ diff --git a/Classes/FactProvider/BrowserAcceptedLanguage.php b/Classes/FactProvider/BrowserAcceptedLanguage.php index bdbfceb..fcccba9 100644 --- a/Classes/FactProvider/BrowserAcceptedLanguage.php +++ b/Classes/FactProvider/BrowserAcceptedLanguage.php @@ -48,9 +48,9 @@ public function process(): self public function isGuilty($prosecution): bool { LocateUtility::mainstreamValue($prosecution); - $this->priority = (int)($this->getSubject()[$prosecution] ?? 0); + $this->priority = (int)($this->facts[$prosecution] ?? 0); - return isset($this->getSubject()[$prosecution]); + return isset($this->facts[$prosecution]); } protected function getAcceptedLanguages(): array diff --git a/Classes/FactProvider/IP2Country.php b/Classes/FactProvider/IP2Country.php index 4245010..b308f70 100644 --- a/Classes/FactProvider/IP2Country.php +++ b/Classes/FactProvider/IP2Country.php @@ -33,7 +33,9 @@ public function getBasename(): string */ public function process(): self { - $iso2 = GeneralUtility::makeInstance(LocateUtility::class)->getCountryIso2FromIP() ?? ''; + $simulateIp = $this->configuration['settings']['simulateIp'] ? : null; + + $iso2 = GeneralUtility::makeInstance(LocateUtility::class)->getCountryIso2FromIP($simulateIp) ?? ''; LocateUtility::mainstreamValue($iso2); $this->facts[$this->getBasename()] = $iso2; @@ -48,6 +50,6 @@ public function isGuilty($prosecution): bool $prosecution = (string)$prosecution; LocateUtility::mainstreamValue($prosecution); - return $this->getSubject() === $prosecution; + return $this->facts[$this->getBasename()] === $prosecution; } } diff --git a/Classes/Judge/Condition.php b/Classes/Judge/Condition.php index fc88bc9..0d330c3 100644 --- a/Classes/Judge/Condition.php +++ b/Classes/Judge/Condition.php @@ -24,7 +24,7 @@ public function adjudicate(AbstractFactProvider $factProvider, int $priority = A { $prosecution = $this->configuration['prosecution'] ?? $this->configuration['prosecution.'] ?? null; - if ($prosecution !== null && $factProvider->isGuilty($prosecution) && isset($this->configuration['verdict'])) { + if ($prosecution !== null && isset($this->configuration['verdict']) && $factProvider->isGuilty($prosecution)) { $this->decision = (new Decision())->withVerdictName($this->configuration['verdict']); $this->decision->setPriority($priority); diff --git a/Classes/Middleware/LanguageRedirectMiddleware.php b/Classes/Middleware/LanguageRedirectMiddleware.php index 5711f5f..bafc875 100644 --- a/Classes/Middleware/LanguageRedirectMiddleware.php +++ b/Classes/Middleware/LanguageRedirectMiddleware.php @@ -43,6 +43,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface 'overrideSessionValue' => (bool)($locateSetup['overrideSessionValue'] ?? 0), 'sessionHandling' => (bool)($locateSetup['sessionHandling'] ?? 0), 'excludeBots' => (bool)($locateSetup['excludeBots'] ?? 1), + 'simulateIp' => $locateSetup['simulateIp'] ? : null, ], ]; diff --git a/Classes/Processor/Court.php b/Classes/Processor/Court.php index bcd9fc6..280029f 100644 --- a/Classes/Processor/Court.php +++ b/Classes/Processor/Court.php @@ -95,7 +95,7 @@ protected function processFacts(): void } /* @var $factProvider AbstractFactProvider */ - $factProvider = GeneralUtility::makeInstance($className); + $factProvider = GeneralUtility::makeInstance($className, $key, $this->configuration); if (!$factProvider instanceof AbstractFactProvider) { throw new IllegalFactProviderException( diff --git a/Configuration/TypoScript/setup-switch_language.txt b/Configuration/TypoScript/example_setup.typoscript similarity index 94% rename from Configuration/TypoScript/setup-switch_language.txt rename to Configuration/TypoScript/example_setup.typoscript index 6d5a2e3..ad5c779 100644 --- a/Configuration/TypoScript/setup-switch_language.txt +++ b/Configuration/TypoScript/example_setup.typoscript @@ -16,6 +16,9 @@ config.tx_locate { # URL Parameter which has to be true when overrideCookie is allowed within action and cookieHandling is enabled overrideQueryParameter = setLang + # Simulate your IP address for countryByIP fact provider (for test purposes only), 109.10.163.98 is a french IP address + simulateIp = 109.10.163.98 + verdicts { redirectToMainlandChina = Leuchtfeuer\Locate\Verdict\Redirect redirectToMainlandChina.url = https://www.example.cn diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index da7b2ca..331f5f4 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -16,13 +16,16 @@ config.tx_locate { # URL Parameter which has to be true when overrideCookie is allowed within action and cookieHandling is enabled overrideQueryParameter = setLang + # Simulate your IP address for countryByIP fact provider (for test purposes only) + simulateIp = + # See example file for configuration verdicts { } facts { - browserAcceptLanguage = Leuchtfeuer\Locate\FactProvider\BrowserAcceptedLanguage - countryByIP = Leuchtfeuer\Locate\FactProvider\IP2Country + #browserAcceptLanguage = Leuchtfeuer\Locate\FactProvider\BrowserAcceptedLanguage + #countryByIP = Leuchtfeuer\Locate\FactProvider\IP2Country } # See example file for configuration From 0a6c48a2782013e5981cb6a51b6f8d51392f4f4d Mon Sep 17 00:00:00 2001 From: kranz Date: Sun, 10 Apr 2022 21:54:43 +0200 Subject: [PATCH 05/10] [TASK] Add PHP version to require constraint --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index c3f2c6e..eb5c696 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ } ], "require": { + "php": ">=7.4 || >=8.0", "typo3/cms-backend": "^10.4 || ^11.5", "typo3/cms-core": "^10.4 || ^11.5", "typo3/cms-extbase": "^10.4 || ^11.5", From 546394d372628b3d07edd8bd014b0ed4d7057a02 Mon Sep 17 00:00:00 2001 From: kranz Date: Tue, 12 Apr 2022 15:34:35 +0200 Subject: [PATCH 06/10] [TASK] Adapt git workflow config --- .github/workflows/ci.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 380282d..5f41001 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - php-version: [7.2, 7.3, 7.4] + php-version: [7.2, 7.3, 7.4, 8.0] steps: - name: Checkout uses: actions/checkout@v2 @@ -32,19 +32,19 @@ jobs: strategy: matrix: experimental: [false] - php-version: [7.2, 7.3, 7.4] - typo3-version: [^10.4] + php-version: [7.4, 8.0] + typo3-version: [^10.4, ^11.5] include: - php-version: 7.4 - typo3-version: 10.4.x-dev - experimental: true + typo3-version: ^10.4 + experimental: false - php-version: 7.4 - typo3-version: ^11.0 + typo3-version: ^11.5 experimental: false - - php-version: 7.4 - typo3-version: dev-master + - php-version: 8.0 + typo3-version: ^11.5 experimental: true env: PHP_VERSION: ${{ matrix.php-version }} From 079c18de0e0e12cf7a779edc2ec70fe6f3cc6c20 Mon Sep 17 00:00:00 2001 From: kranz Date: Tue, 12 Apr 2022 15:51:41 +0200 Subject: [PATCH 07/10] [TASK] Adapt git workflow config --- .github/workflows/ci.yaml | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f41001..c0bf324 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - php-version: [7.2, 7.3, 7.4, 8.0] + php-version: [7.2, 7.3, 7.4, 8.0, 8.1] steps: - name: Checkout uses: actions/checkout@v2 @@ -32,19 +32,43 @@ jobs: strategy: matrix: experimental: [false] - php-version: [7.4, 8.0] - typo3-version: [^10.4, ^11.5] + php-version: [7.4] + typo3-version: [^10.4] include: - php-version: 7.4 - typo3-version: ^10.4 + typo3-version: 10.4.x-dev + experimental: true + + - php-version: 7.4 + typo3-version: ^11.5 experimental: false - php-version: 7.4 + typo3-version: dev-master + experimental: true + + - php-version: 8.0 + typo3-version: 11.5.x-dev + experimental: true + + - php-version: 8.0 typo3-version: ^11.5 experimental: false - php-version: 8.0 + typo3-version: dev-master + experimental: true + + - php-version: 8.1 + typo3-version: 11.5.x-dev + experimental: true + + - php-version: 8.1 typo3-version: ^11.5 + experimental: false + + - php-version: 8.1 + typo3-version: dev-master experimental: true env: PHP_VERSION: ${{ matrix.php-version }} @@ -96,9 +120,10 @@ jobs: composer req typo3/testing-framework typo3/cms-core:"${{ matrix.typo3-version }}" typo3/cms-backend:"${{ matrix.typo3-version }}" typo3/cms-extbase:"${{ matrix.typo3-version }}" typo3/cms-extensionmanager:"${{ matrix.typo3-version }}" typo3/cms-fluid:"${{ matrix.typo3-version }}" typo3/cms-frontend:"${{ matrix.typo3-version }}" export TYPO3_PATH_WEB=$PWD/.Build/web - - name: Run PHP Unit + - name: Run PHPUnit run: | - .Build/bin/phpunit --colors --configuration Tests/Build/FunctionalTests.xml Tests/Functional --bootstrap .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php --coverage-clover=coverage.xml + .Build/bin/phpunit --configuration Tests/Build/FunctionalTests.xml --coverage-clover=coverage.xml + .Build/bin/phpunit --configuration Tests/Build/UnitTests.xml if [[ "${{ matrix.php-version }}" == "7.4" ]] && [[ "${{ matrix.typo3-version }}" == "^10.4" ]]; then bash <(curl -s https://codecov.io/bash) From 7df3f27d49b1d2fd0820ec6fecee5cb863ddd284 Mon Sep 17 00:00:00 2001 From: kranz Date: Tue, 12 Apr 2022 15:53:09 +0200 Subject: [PATCH 08/10] [TASK] Adapt git workflow config --- .github/workflows/ci.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c0bf324..47c001a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - php-version: [7.2, 7.3, 7.4, 8.0, 8.1] + php-version: [7.2, 7.3, 7.4, 8.0] steps: - name: Checkout uses: actions/checkout@v2 @@ -58,18 +58,6 @@ jobs: - php-version: 8.0 typo3-version: dev-master experimental: true - - - php-version: 8.1 - typo3-version: 11.5.x-dev - experimental: true - - - php-version: 8.1 - typo3-version: ^11.5 - experimental: false - - - php-version: 8.1 - typo3-version: dev-master - experimental: true env: PHP_VERSION: ${{ matrix.php-version }} TYPO3_VERSION: ${{ matrix.typo3-version }} From 0bbf121e259438871810433c41dbb40418f270d3 Mon Sep 17 00:00:00 2001 From: kranz Date: Fri, 22 Apr 2022 18:33:00 +0200 Subject: [PATCH 09/10] [TASK] Add documentation for simulating IP address --- Configuration/Services.yaml | 2 +- Documentation/Functions/AssignLanguage/Index.rst | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 404f0c7..0b423d9 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -8,4 +8,4 @@ services: tags: - name: console.command command: locate:update - schedulable: flase + schedulable: false diff --git a/Documentation/Functions/AssignLanguage/Index.rst b/Documentation/Functions/AssignLanguage/Index.rst index 53bdc2f..a842973 100644 --- a/Documentation/Functions/AssignLanguage/Index.rst +++ b/Documentation/Functions/AssignLanguage/Index.rst @@ -214,6 +214,22 @@ Exclude Bots Whether bots should be excluded from the behavior of the extension. This option only takes effect if the :ref:`corresponding Composer package ` has been installed. +.. _functions-assignLanguage-configuration-simulateIp: + +Simulate IP Address +~~~~~~~~~~~~ +.. container:: table-row + + Property + config.tx_locate.simulateIp + Data type + string + Default + empty + Description + Simulate an IP address for countryByIP fact provider. This is meant to be for test purposes only. + It works with IPv4 and IPv6 addresses. + .. _functions-assignLanguage-configuration-verdicts: Verdicts From 767d81ce56437a658a6f783ac2550dc4c3b72ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20R=C3=B6sch?= Date: Tue, 26 Apr 2022 12:05:14 +0200 Subject: [PATCH 10/10] [TASK] Update ci pipeline parameters --- .github/workflows/ci.yaml | 27 ++++++++++----------------- composer.json | 4 ++-- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 47c001a..546cfe2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,10 +9,10 @@ on: jobs: integration: name: Integration tests - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: - php-version: [7.2, 7.3, 7.4, 8.0] + php-version: [7.4, 8.0] steps: - name: Checkout uses: actions/checkout@v2 @@ -27,36 +27,29 @@ jobs: phpunit: needs: integration name: PHP ${{ matrix.php-version }} - T3 ${{ matrix.typo3-version }} - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 continue-on-error: ${{ matrix.experimental }} strategy: matrix: - experimental: [false] - php-version: [7.4] - typo3-version: [^10.4] include: - php-version: 7.4 - typo3-version: 10.4.x-dev - experimental: true + typo3-version: ^10.4 + experimental: false - php-version: 7.4 typo3-version: ^11.5 experimental: false - - php-version: 7.4 - typo3-version: dev-master - experimental: true - - - php-version: 8.0 - typo3-version: 11.5.x-dev - experimental: true - - php-version: 8.0 typo3-version: ^11.5 experimental: false - php-version: 8.0 - typo3-version: dev-master + typo3-version: 11.5.x-dev + experimental: true + + - php-version: 8.1 + typo3-version: dev-main experimental: true env: PHP_VERSION: ${{ matrix.php-version }} diff --git a/composer.json b/composer.json index 56461f1..3708961 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,8 @@ "symfony/console": "^4.4 || ^5.0" }, "require-dev": { - "phpunit/phpunit": "^8.5.21", - "typo3/testing-framework": "^6.11" + "phpunit/phpunit": "^9.5.20", + "typo3/testing-framework": "^6.16" }, "suggest": { "jaybizzle/crawler-detect": "If you do not want to redirect bots.",