Skip to content

Commit

Permalink
tec: Extract a LocaleSorter from OrganizationSorter
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Jan 18, 2023
1 parent a84479c commit 8ad6c22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
30 changes: 30 additions & 0 deletions src/Service/LocaleSorter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

// This file is part of Bileto.
// Copyright 2022-2023 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace App\Service;

use App\Utils\Locales;
use Symfony\Component\HttpFoundation\RequestStack;

class LocaleSorter
{
private RequestStack $requestStack;

public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

protected function getLocale(): string
{
$currentRequest = $this->requestStack->getCurrentRequest();
if ($currentRequest) {
return $currentRequest->getLocale();
} else {
return Locales::DEFAULT_LOCALE;
}
}
}
21 changes: 1 addition & 20 deletions src/Service/OrganizationSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@
namespace App\Service;

use App\Entity\Organization;
use App\Utils\Locales;
use Symfony\Component\HttpFoundation\RequestStack;

class OrganizationSorter
class OrganizationSorter extends LocaleSorter
{
private RequestStack $requestStack;

public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

/**
* @param Organization[] $organizations
*/
Expand All @@ -38,14 +29,4 @@ public function sort(array &$organizations): void
}
});
}

private function getLocale(): string
{
$currentRequest = $this->requestStack->getCurrentRequest();
if ($currentRequest) {
return $currentRequest->getLocale();
} else {
return Locales::DEFAULT_LOCALE;
}
}
}

0 comments on commit 8ad6c22

Please sign in to comment.