PluginProbe
Metricool – Social media and site statistics / trunk
Metricool – Social media and site statistics vtrunk
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Features / UserSettings / Rules / SupportedLanguageRule.php

SupportedLanguageRule.php in Metricool – Social media and site statistics trunk, at app/Features/UserSettings/Rules/SupportedLanguageRule.php

40 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Metricool\Features\UserSettings\Rules;
6
7 use Metricool\Support\Helpers\Collection;
8 use Metricool\Support\Helpers\Storages\LanguagesConfig;
9 use Metricool\Support\Validation\Rules\AbstractRule;
10
11 class SupportedLanguageRule extends AbstractRule
12 {
13 private Collection $languages;
14
15 public function __construct(LanguagesConfig $languages, array $parameters = [])
16 {
17 parent::__construct($parameters);
18
19 $this->languages = new Collection($languages->all());
20 }
21
22 /**
23 * Checks if the value is a language supported by Metricool
24 * @inheritDoc
25 */
26 public function validate(string $field, $value, array $data): void
27 {
28 $isValidLanguage = $this->languages->where('value', $value)->count() > 0;
29 if (!$isValidLanguage) {
30 $this->fail(esc_html(
31 sprintf(
32 // translators: %s is the invalid language code submitted by the user.
33 __('%s is not a supported language', 'metricool'),
34 $value
35 )
36 ));
37 }
38 }
39 }
40