Skip to content

Commit

Permalink
Fix build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Aug 20, 2024
1 parent e45a3c7 commit 3d0df27
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 32 deletions.
9 changes: 9 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;

return (new Configuration())
// Optional integrations
->ignoreErrorsOnPackage('friendsofsymfony/http-cache', [ErrorType::DEV_DEPENDENCY_IN_PROD])
;
19 changes: 18 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@
"php": "^8.1",
"contao/core-bundle": "^4.13 || ^5.0",
"doctrine/dbal": "^2.11 || ^3.0",
"geoip2/geoip2": "~2.0"
"geoip2/geoip2": "~2.0",
"symfony-cmf/routing": "^2.3 || ^3.0",
"symfony/config": "^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.0 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.0 || ^6.0 || ^7.0",
"symfony/http-foundation": "^5.0 || ^6.0 || ^7.0",
"symfony/http-kernel": "^5.0 || ^6.0 || ^7.0",
"symfony/routing": "^5.0 || ^6.0 || ^7.0",
"symfony/service-contracts": "^1.1 || ^2.0 || ^3.0",
"symfony/translation-contracts": "^2.3 || ^3.0"
},
"require-dev": {
"contao/manager-plugin": "^2.9",
Expand All @@ -47,5 +56,13 @@
},
"extra": {
"contao-manager-plugin": "Terminal42\\Geoip2CountryBundle\\ContaoManager\\Plugin"
},
"config": {
"allow-plugins": {
"contao-components/installer": false,
"php-http/discovery": false,
"contao/manager-plugin": false,
"terminal42/contao-build-tools": true
}
}
}
2 changes: 0 additions & 2 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ services:

Terminal42\Geoip2CountryBundle\Backend\CountryPreviewModule:
arguments:
- '@database_connection'
- '@request_stack'
- '@translator'
- '@contao.intl.countries'
- '@contao.csrf.token_manager'
- '%terminal42_geoip2_country.dca_tables%'
public: true

Terminal42\Geoip2CountryBundle\CountryProvider:
Expand Down
22 changes: 0 additions & 22 deletions src/Backend/CountryPreviewModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
use Contao\MaintenanceModuleInterface;
use Contao\SelectMenu;
use Contao\Widget;
use Doctrine\DBAL\Connection;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;
use Terminal42\Geoip2CountryBundle\CountryProvider;

class CountryPreviewModule implements MaintenanceModuleInterface
{
public function __construct(
private readonly Connection $connection,
private readonly RequestStack $requestStack,
private readonly TranslatorInterface $translator,
private readonly Countries $countries,
private readonly ContaoCsrfTokenManager $csrfTokenManager,
private readonly array $supportedTables,
) {
}

Expand Down Expand Up @@ -61,25 +58,6 @@ public function run(): string
return $template->parse();
}

private function getUsedCountries(): array
{
$queries = [];

foreach ($this->supportedTables as $table) {
$queries[] = "SELECT geoip_countries FROM $table WHERE geoip_visibility='show' OR geoip_visibility='hide'";
}

$countries = $this->connection->executeQuery(
'SELECT GROUP_CONCAT(geoip_countries) FROM ('.implode(' UNION ', $queries).') AS result',
)->fetchOne();

if (!$countries) {
return [];
}

return array_values(array_filter(array_unique(explode(',', (string) $countries))));
}

private function generateWidget(string|null $current): Widget
{
$widget = new SelectMenu();
Expand Down
8 changes: 4 additions & 4 deletions src/CountryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class CountryProvider implements ResetInterface

private string|null $databasePath;

private array $requestCountries = [];

/**
* @param Reader|string|null $databasePath
* @var array<string, string>
*/
private array $requestCountries = [];

public function __construct(
$databasePath = null,
Reader|string|null $databasePath = null,
private readonly string $fallbackCountry = 'XX',
) {
if ($databasePath instanceof Reader) {
Expand Down
22 changes: 19 additions & 3 deletions src/EventListener/DcaLoaderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

class DcaLoaderListener
{
/**
* @param array<string> $supportedTables
*/
public function __construct(
private readonly Connection $connection,
private readonly TranslatorInterface $translator,
Expand Down Expand Up @@ -186,7 +189,11 @@ private function addFlagsToTreeView(string $table): void
};
}

private function callPrevious(mixed $previous, array $arguments): mixed
/**
* @param array{0: string, 1: string}|callable|null $previous
* @param array<mixed> $arguments
*/
private function callPrevious(array|callable|null $previous, array $arguments): mixed
{
if (\is_array($previous)) {
return System::importStatic($previous[0])->{$previous[1]}(...$arguments);
Expand All @@ -199,6 +206,9 @@ private function callPrevious(mixed $previous, array $arguments): mixed
return null;
}

/**
* @param array<string|int, mixed> $row
*/
private function generateFlags(array $row): string
{
if (!$this->hasVisibility($row)) {
Expand All @@ -208,14 +218,14 @@ private function generateFlags(array $row): string
$countries = explode(',', (string) $row['geoip_countries']);
$color = 'show' === $row['geoip_visibility'] ? '#b2f986' : '#ff89bf';

$buffer = sprintf(
$buffer = \sprintf(
'<span style="order:3"><span style="all:unset;display:inline-flex;margin-left:5px;padding:3px 2px;vertical-align:middle;background:%s;border-radius:2px;" title="%s">',
$color,
$this->getLabelForCountries($row['geoip_visibility'], $countries),
);

foreach ($countries as $country) {
$buffer .= sprintf(
$buffer .= \sprintf(
'<img style="all:unset;display:block;height:14px;padding:0 2px" src="bundles/terminal42geoip2country/flags/%s.svg" alt="" height="14">',
strtolower($country),
);
Expand All @@ -224,11 +234,17 @@ private function generateFlags(array $row): string
return $buffer.'</span></span>';
}

/**
* @param array<string|int, mixed> $row
*/
private function hasVisibility(array $row): bool
{
return isset($row['geoip_visibility']) && ('show' === $row['geoip_visibility'] || 'hide' === $row['geoip_visibility']);
}

/**
* @param array<int, string> $countries
*/
private function getLabelForCountries(string $visibility, array $countries): string
{
return $this->translator->trans(
Expand Down
3 changes: 3 additions & 0 deletions src/Migration/UppercaseCountryMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class UppercaseCountryMigration extends AbstractMigration
{
/**
* @param array<string> $supportedTables
*/
public function __construct(
private readonly Connection $connection,
private readonly array $supportedTables,
Expand Down

0 comments on commit 3d0df27

Please sign in to comment.