1818
1919class TwigUtil {
2020
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+
2152 /**
2253 * Registering each directory under `_patterns/` as a namespace. For example, `_patterns/00-atoms/` as `@atoms`
2354 * @param {Instance} an instance of the filesystem Loader
@@ -38,48 +69,36 @@ public static function addPaths($filesystemLoader, $patternSourceDir) {
3869 return $ filesystemLoader ;
3970
4071 }
72+
4173 /**
4274 * 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
4675 */
47- public static function loadDateFormats ($ instance ) {
76+ public static function loadDateFormats () {
4877
4978 $ dateFormat = Config::getOption ("twigDefaultDateFormat " );
5079 $ intervalFormat = Config::getOption ("twigDefaultIntervalFormat " );
5180
5281 if ($ dateFormat && $ intervalFormat && !empty ($ dateFormat ) && !empty ($ intervalFormat )) {
53- $ instance ->getExtension ("core " )->setDateFormat ($ dateFormat , $ intervalFormat );
82+ $ this -> instance ->getExtension ("core " )->setDateFormat ($ dateFormat , $ intervalFormat );
5483 }
5584
56- return $ instance ;
57-
5885 }
5986
6087 /**
6188 * 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
6589 */
66- public static function loadDebug ($ instance ) {
90+ public static function loadDebug () {
6791
6892 if (Config::getOption ("twigDebug " )) {
69- $ instance ->addExtension (new \Twig_Extension_Debug ());
93+ $ this -> instance ->addExtension (new \Twig_Extension_Debug ());
7094 }
7195
72- return $ instance ;
73-
7496 }
7597
7698 /**
7799 * 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
81100 */
82- public static function loadFilters ($ instance ) {
101+ public static function loadFilters () {
83102
84103 // load defaults
85104 $ filterDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/filters " ;
@@ -102,7 +121,7 @@ public static function loadFilters($instance) {
102121
103122 // $filter should be defined in the included file
104123 if (isset ($ filter )) {
105- $ instance ->addFilter ($ filter );
124+ $ this -> instance ->addFilter ($ filter );
106125 unset($ filter );
107126 }
108127
@@ -112,17 +131,12 @@ public static function loadFilters($instance) {
112131
113132 }
114133
115- return $ instance ;
116-
117134 }
118135
119136 /**
120137 * 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
124138 */
125- public static function loadFunctions ($ instance ) {
139+ public static function loadFunctions () {
126140
127141 // load defaults
128142 $ functionDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/functions " ;
@@ -145,7 +159,7 @@ public static function loadFunctions($instance) {
145159
146160 // $function should be defined in the included file
147161 if (isset ($ function )) {
148- $ instance ->addFunction ($ function );
162+ $ this -> instance ->addFunction ($ function );
149163 unset($ function );
150164 }
151165
@@ -155,17 +169,12 @@ public static function loadFunctions($instance) {
155169
156170 }
157171
158- return $ instance ;
159-
160172 }
161173
162174 /**
163175 * 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
167176 */
168- public static function loadMacros ($ instance ) {
177+ public static function loadMacros () {
169178
170179 // load defaults
171180 $ macroDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
@@ -185,25 +194,20 @@ public static function loadMacros($instance) {
185194 if ($ baseName [0 ] != "_ " ) {
186195
187196 // 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 ));
189198
190199 }
191200
192201 }
193202
194203 }
195204
196- return $ instance ;
197-
198205 }
199206
200207 /**
201208 * 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
205209 */
206- public static function loadTags ($ instance ) {
210+ public static function loadTags () {
207211
208212 // load defaults
209213 $ tagDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/tags " ;
@@ -226,25 +230,20 @@ public static function loadTags($instance) {
226230
227231 // Project_{filenameBase}_TokenParser should be defined in the include
228232 $ className = "Project_ " .$ file ->getBasename (". " .$ tagExt )."_TokenParser " ;
229- $ instance ->addTokenParser (new $ className ());
233+ $ this -> instance ->addTokenParser (new $ className ());
230234
231235 }
232236
233237 }
234238
235239 }
236240
237- return $ instance ;
238-
239241 }
240242
241243 /**
242244 * 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
246245 */
247- public static function loadTests ($ instance ) {
246+ public static function loadTests () {
248247
249248 // load defaults
250249 $ testDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/tests " ;
@@ -267,7 +266,7 @@ public static function loadTests($instance) {
267266
268267 // $test should be defined in the included file
269268 if (isset ($ test )) {
270- $ instance ->addTest ($ test );
269+ $ this -> instance ->addTest ($ test );
271270 unset($ test );
272271 }
273272
@@ -277,8 +276,6 @@ public static function loadTests($instance) {
277276
278277 }
279278
280- return $ instance ;
281-
282279 }
283280
284281}
0 commit comments