|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
|
6
|
|
|
use Ecodev\Felix\Debug; |
|
7
|
|
|
use Ecodev\Felix\I18n\Translator; |
|
8
|
|
|
use GraphQL\Doctrine\Types; |
|
9
|
|
|
use Laminas\Log\LoggerInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Returns the type registry. |
|
13
|
|
|
*/ |
|
14
|
|
|
function _types(): Types |
|
15
|
|
|
{ |
|
16
|
|
|
global $container; |
|
17
|
|
|
|
|
18
|
|
|
return $container->get(Types::class); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Returns the Entity Manager. |
|
23
|
|
|
*/ |
|
24
|
|
|
function _em(): EntityManager |
|
25
|
|
|
{ |
|
26
|
|
|
global $container; |
|
27
|
|
|
|
|
28
|
16 |
|
return $container->get(EntityManager::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Returns logger. |
|
33
|
|
|
*/ |
|
34
|
|
|
function _log(): LoggerInterface |
|
35
|
|
|
{ |
|
36
|
|
|
global $container; |
|
37
|
|
|
|
|
38
|
4 |
|
return $container->get(LoggerInterface::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Export variables omitting array keys that are strictly numeric. |
|
43
|
|
|
* |
|
44
|
|
|
* By default, it will output result |
|
45
|
|
|
* |
|
46
|
|
|
* @return string string representation of variable |
|
47
|
|
|
*/ |
|
48
|
|
|
function ve(mixed $data, bool $return = false): string |
|
49
|
|
|
{ |
|
50
|
|
|
return Debug::export($data, $return); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Dump all arguments. |
|
55
|
|
|
*/ |
|
56
|
|
|
function v(): void |
|
57
|
|
|
{ |
|
58
|
|
|
var_dump(func_get_args()); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Dump all arguments and die. |
|
63
|
|
|
*/ |
|
64
|
|
|
function w(): never |
|
65
|
|
|
{ |
|
66
|
|
|
$isHtml = (PHP_SAPI !== 'cli'); |
|
67
|
|
|
echo "\n_________________________________________________________________________________________________________________________" . ($isHtml ? '</br>' : '') . "\n"; |
|
68
|
|
|
var_dump(func_get_args()); |
|
|
|
|
|
|
69
|
|
|
echo "\n" . ($isHtml ? '</br>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '<pre>' : '') . "\n"; |
|
70
|
|
|
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
71
|
|
|
echo '' . ($isHtml ? '</pre>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '</br>' : '') . "\n"; |
|
72
|
|
|
exit("script aborted on purpose.\n"); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Translate given message in current language. |
|
77
|
|
|
* |
|
78
|
|
|
* If replacements are given, they will be replaced after translation: |
|
79
|
|
|
* |
|
80
|
|
|
* ```php |
|
81
|
|
|
* _tr('Hello %my-name%', ['my-name' => 'John']); // Bonjour John |
|
82
|
|
|
* ``` |
|
83
|
|
|
* |
|
84
|
|
|
* @param array<string, null|float|int|string> $replacements |
|
85
|
|
|
*/ |
|
86
|
|
|
function _tr(string $message, array $replacements = []): string |
|
87
|
|
|
{ |
|
88
|
|
|
global $container; |
|
89
|
|
|
|
|
90
|
10 |
|
$translator = $container->get(Translator::class); |
|
91
|
10 |
|
$translation = $translator->translate($message); |
|
92
|
10 |
|
if (!$replacements) { |
|
93
|
6 |
|
return $translation; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
4 |
|
$finalReplacements = []; |
|
97
|
4 |
|
foreach ($replacements as $key => $value) { |
|
98
|
4 |
|
$finalReplacements['%' . $key . '%'] = $value; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
4 |
|
return strtr($translation, $finalReplacements); |
|
102
|
|
|
} |
|
103
|
|
|
|