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