Merge branch 'master' into 'master'

Implemented Nette/Latte engine.

This Engine allows for really neat ways to handle templates. It is an optional dependency which will be installed if composer is used.

See merge request !48
This commit is contained in:
Abel Hoogeveen 2016-07-07 13:20:36 +02:00
commit 2cfb926965
4 changed files with 174 additions and 2 deletions

View File

@ -0,0 +1,95 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author TechFuze
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
*
* @link http://fuzeworks.techfuze.net
* @since Version 0.0.1
*
* @version Version 0.0.1
*/
?>
<html>
<head>
<title>Page not found</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background: #ecf0f1;
border-bottom: 1px solid #DDD;
padding: 100px 0 100px;
font-size: 16px;
}
#setupcontainer {
max-width: 950px;
margin-left: auto;
margin-right: auto;
}
.col-centered{
float: none;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='setupcontainer'>
<div class='row'>
<div class='col-lg-12 col-md-4 col-sm-12'>
<div id='contentPanel' class="panel panel-default" style='display:none'>
<div id='1' class="panel-body" style='display:none'>
<p class="lead">Internal Server Error</p>
<p>
The requested page could not be loaded.
</p>
<p>
Our apologies for the inconvenience.
</p>
</div>
</div>
</div>
</div>
</div>
<footer>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script>
var currentPage = 0;
var currentProgress = 0;
start();
function start() {
$("#contentPanel").fadeIn(500);
$("#1").fadeIn(500);
}
</script>
</footer>
</body>
</html>

View File

@ -35,6 +35,7 @@ namespace FuzeWorks;
use FuzeWorks\TemplateEngine\JSONEngine;
use FuzeWorks\TemplateEngine\PHPEngine;
use FuzeWorks\TemplateEngine\SmartyEngine;
use FuzeWorks\TemplateEngine\LatteEngine;
use FuzeWorks\TemplateEngine\TemplateEngine;
/**
@ -479,6 +480,7 @@ class Layout
self::registerEngine(new PHPEngine(), 'PHP', array('php'));
self::registerEngine(new JsonEngine(), 'JSON', array('json'));
self::registerEngine(new SmartyEngine(), 'Smarty', array('tpl'));
self::registerEngine(new LatteEngine(), 'Latte', array('latte'));
self::$engines_loaded = true;
}
}
@ -528,6 +530,7 @@ namespace FuzeWorks\TemplateEngine;
use FuzeWorks\LayoutException;
use Smarty;
use Latte\Engine as Latte;
/**
* Interface that all Template Engines must follow.
@ -752,6 +755,74 @@ class SmartyEngine implements TemplateEngine
}
}
/**
* Wrapper for the Latte Engine from Nette Framework.
*
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
*/
class LatteEngine implements TemplateEngine
{
/**
* Instance of the Latte Engine
*
* @var Latte\Engine The Latte Engine to be used
*/
protected $latte;
/**
* Set the directory of the current template.
*
* @param string $directory Template Directory
*/
public function setDirectory($directory)
{
if (class_exists('\Latte\Engine', true))
{
// If possible, load Latte\Engine
$this->latte = new Latte;
$this->latte->setTempDirectory(realpath('Application'.DS.'Cache'));
}
else
{
throw new LayoutException("Could not load LatteEngine. Is it installed or Composer not loaded?", 1);
}
}
/**
* Handle and retrieve a template file.
*
* @param string $file Template File
* @param array $assigned_variables All the variables used in this view
*
* @return string Output of the template
*/
public function get($file, $assigned_variables)
{
$this->latte->render($file, $assigned_variables);
}
/**
* Retrieve the file extensions that this template engine uses.
*
* @return array All used extensions. eg: array('php')
*/
public function getFileExtensions()
{
return array('latte');
}
/**
* Reset the template engine to its default state, so it can be used again clean.
*/
public function reset()
{
// If possible, load Latte\Engine
$this->latte = null;
}
}
/**
* Template Engine that exports all assigned variables as JSON.
*

View File

@ -205,7 +205,6 @@ class Logger {
// Log it!
Factory::getInstance()->output->set_output('');
self::errorHandler($errno, $errstr, $errfile, $errline);
if (self::$useTracy === false)
{
self::http_error('500');
@ -249,6 +248,11 @@ class Logger {
$context = $exception->getTraceAsString();
self::logError('Exception thrown: ' . $message . ' | ' . $code, null, $file, $line);
// And return a 500 because this error was fatal
if (self::$useTracy === false)
{
self::http_error('500');
}
}
/**
@ -592,6 +596,7 @@ class Logger {
// Try and load the view, if impossible, load HTTP code instead.
try {
Layout::reset();
Layout::view($view);
} catch (LayoutException $exception) {
// No error page could be found, just echo the result

View File

@ -4,7 +4,8 @@
"ext-curl": "*",
"ext-json": "*",
"smarty/smarty": "~3.1",
"tracy/tracy": "*"
"tracy/tracy": "*",
"latte/latte": "*"
},
"require-dev": {
"phpunit/phpunit": "5.3.*",