Skip to content

Instantly share code, notes, and snippets.

@jlamim
Created January 13, 2017 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlamim/afe55937bc7fe4fd7c52f59acdf7fac4 to your computer and use it in GitHub Desktop.
Save jlamim/afe55937bc7fe4fd7c52f59acdf7fac4 to your computer and use it in GitHub Desktop.
Library Blade Template Engine
<?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