-
Notifications
You must be signed in to change notification settings - Fork 0
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
jm-factorin
committed
Jul 18, 2018
0 parents
commit daadee8
Showing
4 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.idea/ | ||
/vendor/ | ||
composer.lock |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "slimcake/templates", | ||
"description": "Additional templating classes for slimcake framework", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=5.3" | ||
}, | ||
"require-dev": { | ||
"twig/twig": "^v1.30" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Slimcake\\Templates\\": "src/" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Slimcake\Templates; | ||
|
||
use Slimcake\Core\View; | ||
|
||
/** | ||
* Class TemplateView | ||
* @package Slimcake\Templates | ||
*/ | ||
class TemplateView extends View | ||
{ | ||
/** @var string $template */ | ||
protected $template; | ||
|
||
/** | ||
* @return mixed|string | ||
* @throws \Slimcake\Core\Exception | ||
*/ | ||
public function build() | ||
{ | ||
$this->set('__contents__', parent::build()); | ||
$this->render($this->template); | ||
|
||
return $this->build(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Slimcake\Templates; | ||
|
||
use Slimcake\Core\Controller; | ||
use Slimcake\Core\Exception; | ||
use Slimcake\Core\View; | ||
|
||
/** | ||
* Class TwigView | ||
* @package Slimcake\Templates | ||
*/ | ||
class TwigView extends View | ||
{ | ||
const EXTENSION = 'twig'; | ||
|
||
/** @var \Twig_Environment $twig */ | ||
protected $twig; | ||
|
||
/** | ||
* @return \Twig_Environment | ||
*/ | ||
protected function getTwig() | ||
{ | ||
return $this->twig; | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws \Twig_Error_Loader | ||
* @throws \Twig_Error_Runtime | ||
* @throws \Twig_Error_Syntax | ||
*/ | ||
protected function extract() | ||
{ | ||
return $this->twig->render($this->render, $this->data); | ||
} | ||
|
||
/** | ||
* TwigView constructor. | ||
* @param Controller $controller | ||
* @throws Exception | ||
*/ | ||
public function __construct(Controller $controller) | ||
{ | ||
parent::__construct($controller); | ||
|
||
if (class_exists(\Twig_Environment::class) === false) { | ||
throw new Exception('Twig library is not installed'); | ||
} | ||
|
||
$loader = new \Twig_Loader_Filesystem(sprintf('%s/', $this->path)); | ||
$this->twig = new \Twig_Environment($loader); | ||
} | ||
} |