1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing global functions. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Core |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Mailcode; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Translation function used to translate internal strings: |
13
|
|
|
* if the localization is installed, it will use this to do |
14
|
|
|
* the translation. |
15
|
|
|
* |
16
|
|
|
* @param string $subject |
17
|
|
|
* @param mixed ...$args |
18
|
|
|
* @return string |
19
|
|
|
*/ |
20
|
|
|
function t(string $subject, ...$args) : string |
21
|
|
|
{ |
22
|
|
|
return \AppLocalize\t($subject, ...$args); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Adds the <code>$</code> sign in front of a variable |
27
|
|
|
* name, if it does not already have it. |
28
|
|
|
* |
29
|
|
|
* @param string $variableName |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
function dollarize(string $variableName) : string |
33
|
|
|
{ |
34
|
|
|
return Mailcode_Variables::dollarizeName($variableName); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Removes the <code>$</code> sign in front of a variable |
39
|
|
|
* name, if present. |
40
|
|
|
* |
41
|
|
|
* @param string $variableName |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
function undollarize(string $variableName) : string |
45
|
|
|
{ |
46
|
|
|
return Mailcode_Variables::undollarizeName($variableName); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param array<mixed,mixed> $array |
51
|
|
|
* @return int|string|null |
52
|
|
|
*/ |
53
|
|
|
function array_key_last(array $array) |
54
|
|
|
{ |
55
|
|
|
$keys = array_keys($array); |
56
|
|
|
return array_pop($keys); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Initializes the utilities: this is called automatically |
61
|
|
|
* because this file is included in the files list in the |
62
|
|
|
* composer.json, guaranteeing it is always loaded. |
63
|
|
|
*/ |
64
|
|
|
function init() : void |
65
|
|
|
{ |
66
|
|
|
if(!class_exists('\AppLocalize\Localization')) { |
67
|
|
|
return; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$installFolder = realpath(__DIR__.'/../'); |
71
|
|
|
|
72
|
|
|
define('MAILCODE_INSTALL_FOLDER', $installFolder); |
73
|
|
|
|
74
|
|
|
// Register the classes as a localization source, |
75
|
|
|
// so they can be found, and use the bundled localization |
76
|
|
|
// files. |
77
|
|
|
\AppLocalize\Localization::addSourceFolder( |
78
|
|
|
'mailcode', |
79
|
|
|
'Mailcode Syntax Parser', |
80
|
|
|
'Composer Packages', |
81
|
|
|
$installFolder.'/localization', |
82
|
|
|
$installFolder.'/src' |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
init(); |
87
|
|
|
|