18
18
19
19
class TwigUtil {
20
20
21
+ protected $ instance = '' ;
22
+
23
+ /**
24
+ * Get an instance of the Twig environment
25
+ *
26
+ * @return {Instance} an instance of the Twig environment
27
+ */
28
+ public static function getInstance () {
29
+
30
+ if (empty ($ this ->instance )) {
31
+ return false ;
32
+ }
33
+
34
+ return $ this ->instance ;
35
+
36
+ }
37
+
38
+ /**
39
+ * Set an instance of the Twig environment
40
+ * @param {Instance} an instance of the Twig environment
41
+ */
42
+ public static function setInstance ($ instance = "" ) {
43
+
44
+ if (empty ($ instance ) || !method_exists ($ instance ,'addGlobal ' )) {
45
+ Console::writeError ("please set the instance " );
46
+ }
47
+
48
+ $ this ->instance = $ instance ;
49
+
50
+ }
51
+
21
52
/**
22
53
* Registering each directory under `_patterns/` as a namespace. For example, `_patterns/00-atoms/` as `@atoms`
23
54
* @param {Instance} an instance of the filesystem Loader
@@ -38,48 +69,36 @@ public static function addPaths($filesystemLoader, $patternSourceDir) {
38
69
return $ filesystemLoader ;
39
70
40
71
}
72
+
41
73
/**
42
74
* Load custom date formats for Twig
43
- * @param {Instance} an instance of the twig engine
44
- *
45
- * @return {Instance} an instance of the twig engine
46
75
*/
47
- public static function loadDateFormats ($ instance ) {
76
+ public static function loadDateFormats () {
48
77
49
78
$ dateFormat = Config::getOption ("twigDefaultDateFormat " );
50
79
$ intervalFormat = Config::getOption ("twigDefaultIntervalFormat " );
51
80
52
81
if ($ dateFormat && $ intervalFormat && !empty ($ dateFormat ) && !empty ($ intervalFormat )) {
53
- $ instance ->getExtension ("core " )->setDateFormat ($ dateFormat , $ intervalFormat );
82
+ $ this -> instance ->getExtension ("core " )->setDateFormat ($ dateFormat , $ intervalFormat );
54
83
}
55
84
56
- return $ instance ;
57
-
58
85
}
59
86
60
87
/**
61
88
* Enable the debug options for Twig
62
- * @param {Instance} an instance of the twig engine
63
- *
64
- * @return {Instance} an instance of the twig engine
65
89
*/
66
- public static function loadDebug ($ instance ) {
90
+ public static function loadDebug () {
67
91
68
92
if (Config::getOption ("twigDebug " )) {
69
- $ instance ->addExtension (new \Twig_Extension_Debug ());
93
+ $ this -> instance ->addExtension (new \Twig_Extension_Debug ());
70
94
}
71
95
72
- return $ instance ;
73
-
74
96
}
75
97
76
98
/**
77
99
* Load filters for the Twig PatternEngine
78
- * @param {Instance} an instance of the twig engine
79
- *
80
- * @return {Instance} an instance of the twig engine
81
100
*/
82
- public static function loadFilters ($ instance ) {
101
+ public static function loadFilters () {
83
102
84
103
// load defaults
85
104
$ filterDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/filters " ;
@@ -102,7 +121,7 @@ public static function loadFilters($instance) {
102
121
103
122
// $filter should be defined in the included file
104
123
if (isset ($ filter )) {
105
- $ instance ->addFilter ($ filter );
124
+ $ this -> instance ->addFilter ($ filter );
106
125
unset($ filter );
107
126
}
108
127
@@ -112,17 +131,12 @@ public static function loadFilters($instance) {
112
131
113
132
}
114
133
115
- return $ instance ;
116
-
117
134
}
118
135
119
136
/**
120
137
* Load functions for the Twig PatternEngine
121
- * @param {Instance} an instance of the twig engine
122
- *
123
- * @return {Instance} an instance of the twig engine
124
138
*/
125
- public static function loadFunctions ($ instance ) {
139
+ public static function loadFunctions () {
126
140
127
141
// load defaults
128
142
$ functionDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/functions " ;
@@ -145,7 +159,7 @@ public static function loadFunctions($instance) {
145
159
146
160
// $function should be defined in the included file
147
161
if (isset ($ function )) {
148
- $ instance ->addFunction ($ function );
162
+ $ this -> instance ->addFunction ($ function );
149
163
unset($ function );
150
164
}
151
165
@@ -155,17 +169,12 @@ public static function loadFunctions($instance) {
155
169
156
170
}
157
171
158
- return $ instance ;
159
-
160
172
}
161
173
162
174
/**
163
175
* Load macros for the Twig PatternEngine
164
- * @param {Instance} an instance of the twig engine
165
- *
166
- * @return {Instance} an instance of the twig engine
167
176
*/
168
- public static function loadMacros ($ instance ) {
177
+ public static function loadMacros () {
169
178
170
179
// load defaults
171
180
$ macroDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
@@ -185,25 +194,20 @@ public static function loadMacros($instance) {
185
194
if ($ baseName [0 ] != "_ " ) {
186
195
187
196
// add the macro to the global context
188
- $ instance ->addGlobal ($ file ->getBasename (". " .$ macroExt ), $ instance ->loadTemplate ($ baseName ));
197
+ $ this -> instance ->addGlobal ($ file ->getBasename (". " .$ macroExt ), $ this -> instance ->loadTemplate ($ baseName ));
189
198
190
199
}
191
200
192
201
}
193
202
194
203
}
195
204
196
- return $ instance ;
197
-
198
205
}
199
206
200
207
/**
201
208
* Load tags for the Twig PatternEngine
202
- * @param {Instance} an instance of the twig engine
203
- *
204
- * @return {Instance} an instance of the twig engine
205
209
*/
206
- public static function loadTags ($ instance ) {
210
+ public static function loadTags () {
207
211
208
212
// load defaults
209
213
$ tagDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/tags " ;
@@ -226,25 +230,20 @@ public static function loadTags($instance) {
226
230
227
231
// Project_{filenameBase}_TokenParser should be defined in the include
228
232
$ className = "Project_ " .$ file ->getBasename (". " .$ tagExt )."_TokenParser " ;
229
- $ instance ->addTokenParser (new $ className ());
233
+ $ this -> instance ->addTokenParser (new $ className ());
230
234
231
235
}
232
236
233
237
}
234
238
235
239
}
236
240
237
- return $ instance ;
238
-
239
241
}
240
242
241
243
/**
242
244
* Load functions for the Twig PatternEngine
243
- * @param {Instance} an instance of the twig engine
244
- *
245
- * @return {Instance} an instance of the twig engine
246
245
*/
247
- public static function loadTests ($ instance ) {
246
+ public static function loadTests () {
248
247
249
248
// load defaults
250
249
$ testDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/tests " ;
@@ -267,7 +266,7 @@ public static function loadTests($instance) {
267
266
268
267
// $test should be defined in the included file
269
268
if (isset ($ test )) {
270
- $ instance ->addTest ($ test );
269
+ $ this -> instance ->addTest ($ test );
271
270
unset($ test );
272
271
}
273
272
@@ -277,8 +276,6 @@ public static function loadTests($instance) {
277
276
278
277
}
279
278
280
- return $ instance ;
281
-
282
279
}
283
280
284
281
}
0 commit comments