Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
<?php | ||
class Template { | ||
private $adaptor; | ||
|
||
public function __construct($adaptor) { | ||
$class = 'Template\\' . $adaptor; | ||
class Template | ||
{ | ||
private $registry; | ||
private $adaptor; | ||
|
||
if (class_exists($class)) { | ||
$this->adaptor = new $class(); | ||
} else { | ||
throw new \Exception('Error: Could not load template adaptor ' . $adaptor . '!'); | ||
} | ||
} | ||
public function __construct($registry) | ||
{ | ||
$this->registry = $registry; | ||
$adaptor = $this->registry->get('config')->get('template_type'); | ||
$class = 'Template\\' . $adaptor; | ||
|
||
public function set($key, $value) { | ||
$this->adaptor->set($key, $value); | ||
} | ||
if (class_exists($class)) { | ||
$this->adaptor = new $class($this->registry); | ||
} else { | ||
throw new \Exception('Error: Could not load template adaptor ' . $adaptor . '!'); | ||
} | ||
} | ||
|
||
public function set($key, $value) | ||
{ | ||
$this->adaptor->set($key, $value); | ||
} | ||
|
||
public function render($template) | ||
{ | ||
return $this->adaptor->render($template); | ||
} | ||
|
||
public function render($template) { | ||
return $this->adaptor->render($template); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
<?php | ||
|
||
namespace Template; | ||
final class PHP { | ||
private $data = array(); | ||
|
||
public function set($key, $value) { | ||
$this->data[$key] = $value; | ||
} | ||
|
||
public function render($template) { | ||
$file = DIR_TEMPLATE . $template; | ||
|
||
if (is_file($file)) { | ||
extract($this->data); | ||
final class PHP | ||
{ | ||
private $registry; | ||
private $data = array(); | ||
|
||
public function __construct($registry) | ||
{ | ||
$this->registry = $registry; | ||
} | ||
|
||
public function set($key, $value) | ||
{ | ||
$this->data[$key] = $value; | ||
} | ||
|
||
public function render($template) | ||
{ | ||
$file = DIR_TEMPLATE . $template; | ||
|
||
if (is_file($file)) { | ||
extract($this->data); | ||
|
||
ob_start(); | ||
|
||
ob_start(); | ||
require($file); | ||
|
||
require($file); | ||
return ob_get_clean(); | ||
} | ||
|
||
return ob_get_clean(); | ||
} | ||
trigger_error('Error: Could not load template ' . $file . '!'); | ||
exit(); | ||
} | ||
|
||
trigger_error('Error: Could not load template ' . $file . '!'); | ||
exit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
<?php | ||
|
||
namespace Template; | ||
final class PHP { | ||
private $data = array(); | ||
|
||
public function set($key, $value) { | ||
$this->data[$key] = $value; | ||
} | ||
|
||
public function render($template) { | ||
$loader = new Twig_Loader_Array(array( | ||
'index' => 'Hello {{ name }}!', | ||
)); | ||
|
||
$twig = new Twig_Environment($loader); | ||
|
||
$file = DIR_TEMPLATE . $template; | ||
|
||
if (is_file($file)) { | ||
extract($this->data); | ||
|
||
ob_start(); | ||
|
||
require($file); | ||
|
||
return ob_get_clean(); | ||
} | ||
|
||
trigger_error('Error: Could not load template ' . $file . '!'); | ||
exit(); | ||
} | ||
|
||
final class PHP | ||
{ | ||
private $registry; | ||
private $data = array(); | ||
|
||
public function __construct($registry) | ||
{ | ||
$this->registry = $registry; | ||
} | ||
|
||
public function set($key, $value) | ||
{ | ||
$this->data[$key] = $value; | ||
} | ||
|
||
public function render($template) | ||
{ | ||
$loader = new Twig_Loader_Array(array( | ||
'index' => 'Hello {{ name }}!', | ||
)); | ||
|
||
$twig = new Twig_Environment($loader); | ||
|
||
$file = DIR_TEMPLATE . $template; | ||
|
||
if (is_file($file)) { | ||
extract($this->data); | ||
|
||
ob_start(); | ||
|
||
require($file); | ||
|
||
return ob_get_clean(); | ||
} | ||
|
||
trigger_error('Error: Could not load template ' . $file . '!'); | ||
exit(); | ||
} | ||
|
||
} |