Skip to content

Commit 163f802

Browse files
committed
added autoloading
1 parent 174c42e commit 163f802

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

src/Core/Core.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
namespace Core;
4-
54
use \Core\TwigCore;
65

76
class Core

src/Core/TwigCore.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

src/View/View.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}

0 commit comments

Comments
 (0)