-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #152 Process locales to match paypal requirements (SirDomin, Zale…
…s0123) This PR was merged into the 1.0-dev branch. Discussion ---------- fixes #131 Commits ------- 1dfe4ad process locales to match paypal requirements 4cf8151 use locale from symfony ebc657f Support more than 5-signs locales properly
- Loading branch information
Showing
7 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\PayPalPlugin\Processor; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
final class LocaleProcessorSpec extends ObjectBehavior | ||
{ | ||
function it_always_processes_locale_to_version_with_region(): void | ||
{ | ||
$this->process('et')->shouldReturn('et_EE'); | ||
$this->process('pl')->shouldReturn('pl_PL'); | ||
$this->process('ja')->shouldReturn('ja_JP'); | ||
} | ||
|
||
function it_returns_same_locale_if_it_is_valid(): void | ||
{ | ||
$this->process('it_IT')->shouldReturn('it_IT'); | ||
$this->process('ja_JP_TRADITIONAL')->shouldReturn('ja_JP_TRADITIONAL'); | ||
$this->process('sd_Arab_PK')->shouldReturn('sd_Arab_PK'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\PayPalPlugin\Processor; | ||
|
||
use Symfony\Component\Intl\Locales; | ||
|
||
final class LocaleProcessor implements LocaleProcessorInterface | ||
{ | ||
public function process(string $locale): string | ||
{ | ||
if ($this->isValidLocale($locale)) { | ||
return $locale; | ||
} | ||
|
||
$locales = array_filter(Locales::getLocales(), function (string $targetLocale) use ($locale): bool { | ||
return | ||
strpos($targetLocale, $locale) === 0 && | ||
strpos($targetLocale, '_') !== false | ||
; | ||
}); | ||
|
||
return $locales[array_key_first($locales)]; | ||
} | ||
|
||
private function isValidLocale(string $locale): bool | ||
{ | ||
return strpos($locale, '_') !== false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\PayPalPlugin\Processor; | ||
|
||
interface LocaleProcessorInterface | ||
{ | ||
public function process(string $locale): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters