1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* ReportingCloud PHP SDK |
6
|
|
|
* |
7
|
|
|
* PHP SDK for ReportingCloud Web API. Authored and supported by Text Control GmbH. |
8
|
|
|
* |
9
|
|
|
* @link https://www.reporting.cloud to learn more about ReportingCloud |
10
|
|
|
* @link https://git.io/Jejj2 for the canonical source repository |
11
|
|
|
* @license https://git.io/Jejjr |
12
|
|
|
* @copyright © 2022 Text Control GmbH |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TxTextControl\ReportingCloud\Assert; |
16
|
|
|
|
17
|
|
|
use TxTextControl\ReportingCloud\Exception\InvalidArgumentException; |
18
|
|
|
use TxTextControl\ReportingCloud\Stdlib\Path; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Trait AssertLanguageTrait |
22
|
|
|
* |
23
|
|
|
* @package TxTextControl\ReportingCloud |
24
|
|
|
* @author Jonathan Maron (@JonathanMaron) |
25
|
|
|
*/ |
26
|
|
|
trait AssertCultureTrait |
27
|
|
|
{ |
28
|
|
|
use ValueToStringTrait; |
29
|
|
|
use AssertOneOfTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Check value is a valid culture |
33
|
|
|
* |
34
|
|
|
* @param string $value |
35
|
|
|
* @param string $message |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
* @throws InvalidArgumentException |
39
|
|
|
*/ |
40
|
8 |
|
public static function assertCulture(string $value, string $message = ''): void |
41
|
|
|
{ |
42
|
8 |
|
$haystack = self::getCultures(); |
43
|
8 |
|
$format = 0 === strlen($message) ? '%1$s contains an unsupported culture' : $message; |
44
|
8 |
|
$message = sprintf($format, self::valueToString($value)); |
45
|
|
|
|
46
|
8 |
|
self::assertOneOf($value, $haystack, $message); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Return the filename, containing cultures array |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
8 |
|
public static function getCulturesFilename(): string |
55
|
|
|
{ |
56
|
8 |
|
return sprintf('%1$s/cultures.php', Path::data()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Return cultures array |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
8 |
|
private static function getCultures(): array |
65
|
|
|
{ |
66
|
8 |
|
$filename = self::getCulturesFilename(); |
67
|
|
|
|
68
|
8 |
|
return (array) include $filename; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|