Skip to content

Commit

Permalink
[CS] Refactor (#173)
Browse files Browse the repository at this point in the history
Co-authored-by: DACHCOM Bot <[email protected]>
  • Loading branch information
github-actions[bot] and DACHCOM Bot authored Dec 4, 2024
1 parent 5930192 commit d4a83f7
Show file tree
Hide file tree
Showing 102 changed files with 1,225 additions and 138 deletions.
11 changes: 11 additions & 0 deletions src/Adapter/LocaleProvider/AbstractLocaleProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\LocaleProvider;

abstract class AbstractLocaleProvider implements LocaleProviderInterface
Expand Down
11 changes: 11 additions & 0 deletions src/Adapter/LocaleProvider/LocaleProviderInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\LocaleProvider;

use I18nBundle\Model\ZoneInterface;
Expand Down
11 changes: 11 additions & 0 deletions src/Adapter/LocaleProvider/SystemLocaleProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\LocaleProvider;

use I18nBundle\Definitions;
Expand Down
11 changes: 11 additions & 0 deletions src/Adapter/PathGenerator/AbstractPathGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\PathGenerator;

use I18nBundle\Transformer\AlternateRouteItemTransformer;
Expand Down
14 changes: 12 additions & 2 deletions src/Adapter/PathGenerator/Document.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\PathGenerator;

use I18nBundle\Context\I18nContextInterface;
Expand Down Expand Up @@ -91,7 +102,6 @@ private function resolveDocumentRoutes(I18nContextInterface $i18nContext, Pimcor
}

foreach ($zoneSites as $zoneSite) {

if (empty($zoneSite->getLocale())) {
continue;
}
Expand All @@ -104,6 +114,7 @@ private function resolveDocumentRoutes(I18nContextInterface $i18nContext, Pimcor
if ($zoneSite->getType() === 'hardlink') {
$virtualProxyZoneSites[] = $zoneSite;
}

continue;
}

Expand Down Expand Up @@ -135,7 +146,6 @@ private function resolveDocumentRoutes(I18nContextInterface $i18nContext, Pimcor
}

foreach ($virtualProxyZoneSites as $virtualProxyZoneSite) {

$sameLanguageContextIndex = array_search($virtualProxyZoneSite->getLanguageIso(), array_column($routes, 'languageIso'), true);
if ($sameLanguageContextIndex === false) {
continue;
Expand Down
13 changes: 11 additions & 2 deletions src/Adapter/PathGenerator/DynamicRoute.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\PathGenerator;

use I18nBundle\Context\I18nContextInterface;
Expand Down Expand Up @@ -37,7 +48,6 @@ protected function buildAlternateRoutesStack(I18nContextInterface $i18nContext,
$this->eventDispatcher->dispatch($event, $eventName);

foreach ($event->getAlternateRouteItems() as $alternateRouteItem) {

if ($alternateRouteItem->isValidAlternateRoute() === false) {
continue;
}
Expand All @@ -55,4 +65,3 @@ protected function buildAlternateRoutesStack(I18nContextInterface $i18nContext,
return $routes;
}
}

11 changes: 11 additions & 0 deletions src/Adapter/PathGenerator/PathGeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\PathGenerator;

use I18nBundle\Context\I18nContextInterface;
Expand Down
12 changes: 11 additions & 1 deletion src/Adapter/PathGenerator/StaticRoute.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\PathGenerator;

use I18nBundle\Context\I18nContextInterface;
Expand Down Expand Up @@ -45,4 +56,3 @@ protected function generateLink(AlternateRouteItemInterface $routeItem): string
return $this->router->generate($routeItem->getRouteName() ?? '', $routeParameters, UrlGeneratorInterface::ABSOLUTE_URL);
}
}

13 changes: 12 additions & 1 deletion src/Adapter/PathGenerator/Symfony.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\PathGenerator;

use I18nBundle\Context\I18nContextInterface;
use I18nBundle\I18nEvents;
use I18nBundle\Model\RouteItem\AlternateRouteItemInterface;
use I18nBundle\Model\RouteItem\RouteItemInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Symfony extends DynamicRoute
{
Expand Down
11 changes: 11 additions & 0 deletions src/Adapter/Redirector/AbstractRedirector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\Redirector;

use Symfony\Component\OptionsResolver\OptionsResolver;
Expand Down
22 changes: 16 additions & 6 deletions src/Adapter/Redirector/CookieRedirector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\Redirector;

use I18nBundle\Helper\CookieHelper;
Expand All @@ -8,7 +19,6 @@

class CookieRedirector extends AbstractRedirector
{

public function makeDecision(RedirectorBag $redirectorBag): void
{
$cookieHelper = new CookieHelper($this->config['cookie']);
Expand Down Expand Up @@ -48,16 +58,16 @@ protected function getConfigResolver(): OptionsResolver
{
$resolver = new OptionsResolver();
$resolver->setRequired('cookie');
$resolver->setDefault('cookie', function(OptionsResolver $cookieResolver) {
$resolver->setDefault('cookie', function (OptionsResolver $cookieResolver) {
$cookieResolver
->setRequired(['path', 'domain', 'secure', 'http_only', 'same_site'])
->setDefaults([
'path' => '/',
'domain' => null,
'secure' => false,
'path' => '/',
'domain' => null,
'secure' => false,
'http_only' => true,
'same_site' => Cookie::SAMESITE_LAX,
'expire' => '+1 year'
'expire' => '+1 year'
])
->setAllowedTypes('path', 'string')
->setAllowedTypes('domain', ['string', 'null'])
Expand Down
12 changes: 12 additions & 0 deletions src/Adapter/Redirector/FallbackRedirector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\Redirector;

use I18nBundle\Model\ZoneSiteInterface;
Expand All @@ -20,6 +31,7 @@ public function makeDecision(RedirectorBag $redirectorBag): void

if (!$zoneSite instanceof ZoneSiteInterface) {
$this->setDecision(['valid' => false]);

return;
}

Expand Down
34 changes: 22 additions & 12 deletions src/Adapter/Redirector/GeoRedirector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\Redirector;

use I18nBundle\Helper\UserHelper;
Expand All @@ -23,7 +34,7 @@ public function makeDecision(RedirectorBag $redirectorBag): void

/**
* - Based on string source HTTP_ACCEPT_LANGUAGE ("de,en;q=0.9,de-DE;q=0.8;...")
* - Transformed by symfony to [de, en, de_DE, ...]
* - Transformed by symfony to [de, en, de_DE, ...].
*/
$userLanguagesIso = $this->userHelper->getLanguagesAcceptedByUser();

Expand Down Expand Up @@ -52,7 +63,6 @@ public function makeDecision(RedirectorBag $redirectorBag): void

foreach ($prioritisedList as $index => $list) {
foreach ($userLanguagesIso as $priority => $userLocale) {

$country = $list['ignore_country'] ? null : $userCountryIso;
$countryStrictMode = $list['strict_country'];
$languageStrictMode = $list['strict_language'];
Expand All @@ -62,6 +72,7 @@ public function makeDecision(RedirectorBag $redirectorBag): void
'priority' => $index === 0 ? -1 : $priority,
'site' => $zoneSite
];

break;
}
}
Expand All @@ -70,6 +81,7 @@ public function makeDecision(RedirectorBag $redirectorBag): void
// nothing found.
if (count($prioritisedListQuery) === 0) {
$this->setDecision(['valid' => false, 'redirectorOptions' => $redirectorOptions]);

return;
}

Expand Down Expand Up @@ -97,11 +109,9 @@ protected function findZoneSite(
bool $countryStrictMode = true,
bool $languageStrictMode = false
): ?ZoneSiteInterface {

$locale = $languageStrictMode ? substr($locale, 0, 2) : $locale;

if ($countryIso === null) {

$indexId = array_search($locale, array_map(static function (ZoneSiteInterface $site) {
return $site->getLocale();
}, $zoneSites), true);
Expand Down Expand Up @@ -143,14 +153,14 @@ protected function getConfigResolver(): OptionsResolver
$resolver = new OptionsResolver();
$resolver
->setRequired('rules')
->setDefault('rules', function(OptionsResolver $rulesResolver) {
$rulesResolver
->setPrototype(true)
->setRequired(['ignore_country', 'strict_country', 'strict_language'])
->setAllowedTypes('ignore_country', 'bool')
->setAllowedTypes('strict_country', 'bool')
->setAllowedTypes('strict_language', 'bool');
});
->setDefault('rules', function (OptionsResolver $rulesResolver) {
$rulesResolver
->setPrototype(true)
->setRequired(['ignore_country', 'strict_country', 'strict_language'])
->setAllowedTypes('ignore_country', 'bool')
->setAllowedTypes('strict_country', 'bool')
->setAllowedTypes('strict_language', 'bool');
});

return $resolver;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Adapter/Redirector/RedirectorBag.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace I18nBundle\Adapter\Redirector;

use I18nBundle\Context\I18nContextInterface;
Expand Down
Loading

0 comments on commit d4a83f7

Please sign in to comment.