Created
January 13, 2017 14:36
-
-
Save jlamim/afe55937bc7fe4fd7c52f59acdf7fac4 to your computer and use it in GitHub Desktop.
Library Blade Template Engine
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
<?php | |
defined('BASEPATH') or exit('No direct script access allowed'); | |
/** | |
* Blade Integration Class | |
* | |
* Classe utilizada para integração entre o CodeIgniter e a Blade Template Engine | |
*/ | |
class Blade | |
{ | |
public function __construct() | |
{ | |
// define os diretórios onde estarão armazenadas as views e o cache | |
$path = [ | |
APPPATH . 'views/' | |
]; | |
$cachePath = APPPATH . 'cache/views'; | |
// aplica as devidas configurações e instanciações da Blade Template Engine | |
$compiler = new \Xiaoler\Blade\Compilers\BladeCompiler($cachePath); | |
$engine = new \Xiaoler\Blade\Engines\CompilerEngine($compiler); | |
$finder = new \Xiaoler\Blade\FileViewFinder($path); | |
$finder->addExtension('php'); | |
$this->factory = new \Xiaoler\Blade\Factory($engine, $finder); | |
} | |
/* | |
* Os métodos criados a seguir servirão para que você possa utilizar os | |
* recursos de carregamento das views usando, por exemplo, | |
* $this->blade->view() | |
*/ | |
public function view($path, $vars = []) | |
{ | |
echo $this->factory->make($path, $vars); | |
} | |
public function exists($path) | |
{ | |
return $this->factory->exists($path); | |
} | |
public function share($key, $value) | |
{ | |
return $this->factory->share($key, $value); | |
} | |
public function render($path, $vars = []) | |
{ | |
return $this->factory->make($path, $vars)->render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment