File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?php
22
33 namespace Core ;
4-
54 use \Core \TwigCore ;
65
76 class Core
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class TwigCore
1212 public static function factorize ()
1313 {
1414 self ::$ loader = new \Twig_Loader_Filesystem (base_path ().'/views ' );
15- self ::$ twig = new \Twig_Environment ($ loader , Core::config ('twig ' ));
15+ self ::$ twig = new \Twig_Environment (self ::$ loader , Core::config ('twig ' ));
16+ return $ twig ;
1617 }
1718 }
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace View ;
3+ use \Core \Core ;
4+ use \Core \TwigCore ;
5+
6+ class View
7+ {
8+
9+ private $ filePath = "" ;
10+ private static $ instance = null ;
11+
12+ /*
13+ * Factorize loads the given parameter to a new View instance
14+ * @params $filePath of the view template
15+ * @returns the instance generated by factorize
16+ */
17+ public static function factorize ($ file )
18+ {
19+ self ::$ instance = new View ;
20+ self ::$ instance ->setPath ($ file );
21+ return self ::$ instance ;
22+ }
23+
24+ /*
25+ * SetPath is a function to point the template to the correct filepath
26+ * @params file location relative to app/views
27+ * @returns instance of the view component
28+ */
29+ public function setPath ($ filePath )
30+ {
31+ $ this ->filePath = $ filePath ;
32+ return $ this ;
33+ }
34+
35+ /*
36+ * Load will load the given filepath to the browser. it will not 'echo' the file rather, it'll return it
37+ * @params $parms an array of variables needed to load the function
38+ * @returns a rendered html file
39+ */
40+ public function load ($ parms = array ())
41+ {
42+ return TwigCore::$ twig ->render ($ this ->filePath , $ parms );
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments