1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CalendR\Bridge\Twig; |
4
|
|
|
|
5
|
|
|
use CalendR\Calendar; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Extension for using periods and events from Twig |
9
|
|
|
* |
10
|
|
|
* @author Yohan Giarelli <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class CalendRExtension extends \Twig_Extension |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Calendar |
16
|
|
|
*/ |
17
|
|
|
protected $factory; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param Calendar $factory |
21
|
|
|
*/ |
22
|
|
|
public function __construct(Calendar $factory) |
23
|
|
|
{ |
24
|
|
|
$this->factory = $factory; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return array<\Twig_Function> |
29
|
|
|
*/ |
30
|
|
|
public function getFunctions() |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
new \Twig_SimpleFunction('calendr_year', [$this, 'getYear']), |
34
|
|
|
new \Twig_SimpleFunction('calendr_month', [$this, 'getMonth']), |
35
|
|
|
new \Twig_SimpleFunction('calendr_week', [$this, 'getWeek']), |
36
|
|
|
new \Twig_SimpleFunction('calendr_day', [$this, 'getDay']), |
37
|
|
|
new \Twig_SimpleFunction('calendr_events', [$this, 'getEvents']), |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function getYear() |
45
|
|
|
{ |
46
|
|
|
return call_user_func_array([$this->factory, 'getYear'], func_get_args()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
public function getMonth() |
53
|
|
|
{ |
54
|
|
|
return call_user_func_array([$this->factory, 'getMonth'], func_get_args()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
|
|
public function getWeek() |
61
|
|
|
{ |
62
|
|
|
return call_user_func_array([$this->factory, 'getWeek'], func_get_args()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
public function getDay() |
69
|
|
|
{ |
70
|
|
|
return call_user_func_array([$this->factory, 'getDay'], func_get_args()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return mixed |
75
|
|
|
*/ |
76
|
|
|
public function getEvents() |
77
|
|
|
{ |
78
|
|
|
return call_user_func_array([$this->factory, 'getEvents'], func_get_args()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function getName() |
85
|
|
|
{ |
86
|
|
|
return self::class; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|