blob: 1a4df42c572dcc62330967fc2bc2883274d8480a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?php
namespace Engelsystem\Renderer\Twig\Extensions;
use Carbon\Carbon;
use Twig_Extension as TwigExtension;
use Twig_Extension_GlobalsInterface as GlobalsInterface;
class Globals extends TwigExtension implements GlobalsInterface
{
/**
* Returns a list of global variables to add to the existing list.
*
* @return array An array of global variables
*/
public function getGlobals()
{
global $user;
$eventConfig = $this->getEventConfig();
if (empty($eventConfig)) {
$eventConfig = [];
}
return [
'user' => isset($user) ? $user : [],
'event_config' => $this->filterEventConfig($eventConfig),
];
}
/**
* @return array
* @codeCoverageIgnore
*/
protected function getEventConfig()
{
return EventConfig();
}
/**
* @param $eventConfig
* @return mixed
*/
protected function filterEventConfig($eventConfig)
{
array_walk($eventConfig, function (&$value, $key) {
if (is_null($value) || !in_array($key, [
'buildup_start_date',
'event_start_date',
'event_end_date',
'teardown_end_date',
])) {
return;
}
$value = Carbon::createFromTimestamp($value);
});
return $eventConfig;
}
}
|