Rewritten the Layout system to use 'layout.' files instead of 'view.' files.
- All systems have been rewritten to use this new scheme.
This commit is contained in:
parent
c2ac27d637
commit
457987e2f1
|
@ -1744,7 +1744,7 @@ abstract class FW_DB_driver {
|
|||
* @param string the error message
|
||||
* @param string any "swap" values
|
||||
* @param bool whether to localize the message
|
||||
* @return string sends the application/views/errors/error_db.php template
|
||||
* @return string sends the application/layout/errors/error_db.php template
|
||||
*/
|
||||
public function display_error($error = '', $swap = '', $native = FALSE)
|
||||
{
|
||||
|
|
|
@ -127,7 +127,7 @@ class DatabaseTracyBridge implements IBarPanel
|
|||
{
|
||||
$results = $this->getResults();
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . '/Views/view.tracydatabasetab.php';
|
||||
require dirname(__DIR__) . '/Layout/layout.tracydatabasetab.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ class DatabaseTracyBridge implements IBarPanel
|
|||
// Parse the panel
|
||||
$results = $this->getResults();
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . '/Views/view.tracydatabasepanel.php';
|
||||
require dirname(__DIR__) . '/Layout/layout.tracydatabasepanel.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
|
@ -35,24 +35,24 @@ namespace FuzeWorks\Event;
|
|||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a view is loaded.
|
||||
* Event that gets loaded when a layout is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a view, or change the file or engine of a view
|
||||
* Use this to cancel the loading of a layout, or change the file or engine of a layout
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class LayoutLoadViewEvent extends Event
|
||||
class LayoutLoadEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directory of the view to be loaded.
|
||||
* The directory of the layout to be loaded.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $directory;
|
||||
|
||||
/**
|
||||
* The file of the view to be loaded.
|
||||
* The file of the layout to be loaded.
|
||||
*
|
||||
* @var string
|
||||
*/
|
|
@ -98,14 +98,14 @@ class Layout
|
|||
|
||||
public function init()
|
||||
{
|
||||
$this->directory = Core::$appDir . DS .'Views';
|
||||
$this->directory = Core::$appDir . DS .'Layout';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a template file using a string and a directory and immediatly parse it to the output class.
|
||||
*
|
||||
* What template file gets loaded depends on the template engine that is being used.
|
||||
* PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file.
|
||||
* PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/layout.dashboard.php file.
|
||||
* You can also provide no particular engine, and the manager will decide what template to load.
|
||||
* Remember that doing so will result in a LayoutException when multiple compatible files are found.
|
||||
*
|
||||
|
@ -115,7 +115,7 @@ class Layout
|
|||
*
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public function view($file, $directory = null, $directOutput = false)
|
||||
public function display($file, $directory = null, $directOutput = false)
|
||||
{
|
||||
$output = Factory::getInstance()->output;
|
||||
$directory = (is_null($directory) ? $this->directory : $directory);
|
||||
|
@ -136,7 +136,7 @@ class Layout
|
|||
* Retrieve a template file using a string and a directory.
|
||||
*
|
||||
* What template file gets loaded depends on the template engine that is being used.
|
||||
* PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file.
|
||||
* PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/layout.dashboard.php file.
|
||||
* You can also provide no particular engine, and the manager will decide what template to load.
|
||||
* Remember that doing so will result in a LayoutException when multiple compatible files are found.
|
||||
*
|
||||
|
@ -177,7 +177,7 @@ class Layout
|
|||
$this->current_engine->setDirectory($this->directory);
|
||||
|
||||
// And run an Event to see what other parts have to say about it
|
||||
$event = Events::fireEvent('layoutLoadViewEvent', $this->file, $this->directory, $this->current_engine, $this->assigned_variables);
|
||||
$event = Events::fireEvent('layoutLoadEvent', $this->file, $this->directory, $this->current_engine, $this->assigned_variables);
|
||||
|
||||
// The event has been cancelled
|
||||
if ($event->isCancelled()) {
|
||||
|
@ -227,7 +227,7 @@ class Layout
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts a view string to a file using the directory and the used extensions.
|
||||
* Converts a layout string to a file using the directory and the used extensions.
|
||||
*
|
||||
* It will detect whether the file exists and choose a file according to the provided extensions
|
||||
*
|
||||
|
@ -253,30 +253,30 @@ class Layout
|
|||
}
|
||||
|
||||
// Set the file name and location
|
||||
$viewSelector = explode('/', $string);
|
||||
if (count($viewSelector) == 1) {
|
||||
$viewSelector = 'view.'.$viewSelector[0];
|
||||
$layoutSelector = explode('/', $string);
|
||||
if (count($layoutSelector) == 1) {
|
||||
$layoutSelector = 'layout.'.$layoutSelector[0];
|
||||
} else {
|
||||
// Get last file
|
||||
$file = end($viewSelector);
|
||||
$file = end($layoutSelector);
|
||||
|
||||
// Reset to start
|
||||
reset($viewSelector);
|
||||
reset($layoutSelector);
|
||||
|
||||
// Remove last value
|
||||
array_pop($viewSelector);
|
||||
array_pop($layoutSelector);
|
||||
|
||||
$viewSelector[] = 'view.'.$file;
|
||||
$layoutSelector[] = 'layout.'.$file;
|
||||
|
||||
// And create the final value
|
||||
$viewSelector = implode('/', $viewSelector);
|
||||
$layoutSelector = implode('/', $layoutSelector);
|
||||
}
|
||||
|
||||
// Then try and select a file
|
||||
$fileSelected = false;
|
||||
$selectedFile = null;
|
||||
foreach ($extensions as $extension) {
|
||||
$file = $directory.$viewSelector.'.'.strtolower($extension);
|
||||
$file = $directory.$layoutSelector.'.'.strtolower($extension);
|
||||
$file = preg_replace('#/+#', '/', $file);
|
||||
if (file_exists($file) && !$fileSelected) {
|
||||
$selectedFile = $file;
|
||||
|
@ -296,7 +296,7 @@ class Layout
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts a view string to a file using the directory and the used extensions.
|
||||
* Converts a layout string to a file using the directory and the used extensions.
|
||||
* It also sets the file variable of this class.
|
||||
*
|
||||
* It will detect whether the file exists and choose a file according to the provided extensions
|
||||
|
@ -527,7 +527,7 @@ class Layout
|
|||
|
||||
$this->current_engine = null;
|
||||
$this->assigned_variables = array();
|
||||
$this->directory = Core::$appDir . DS . 'Views';
|
||||
$this->directory = Core::$appDir . DS . 'Layout';
|
||||
Logger::log('Reset the layout manager to its default state');
|
||||
}
|
||||
}
|
|
@ -244,7 +244,7 @@ class Logger {
|
|||
}
|
||||
|
||||
$logs = self::$Logs;
|
||||
require(dirname(__DIR__) . '/Views/view.' . self::$logger_template . '.php');
|
||||
require(dirname(__DIR__) . '/Layout/layout.' . self::$logger_template . '.php');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -255,7 +255,7 @@ class Logger {
|
|||
{
|
||||
ob_start(function () {});
|
||||
$logs = self::$Logs;
|
||||
require(dirname(__DIR__) . '/Views/view.logger_cli.php');
|
||||
require(dirname(__DIR__) . '/Layout/layout.logger_cli.php');
|
||||
$contents = ob_get_clean();
|
||||
$file = Core::$logDir .DS. 'Logs'.DS.'log_latest.php';
|
||||
if (is_writable($file))
|
||||
|
@ -463,9 +463,9 @@ class Logger {
|
|||
* Calls an HTTP error, sends it as a header, and loads a template if required to do so.
|
||||
*
|
||||
* @param int $errno HTTP error code
|
||||
* @param bool $view true to view error on website
|
||||
* @param bool $layout true to layout error on website
|
||||
*/
|
||||
public static function http_error($errno = 500, $view = true) {
|
||||
public static function http_error($errno = 500, $layout = true) {
|
||||
$http_codes = array(
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
|
@ -506,20 +506,20 @@ class Logger {
|
|||
self::log('Sending header HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
|
||||
header('HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
|
||||
|
||||
// Do we want the error-view with it?
|
||||
if ($view == false) {
|
||||
// Do we want the error-layout with it?
|
||||
if ($layout == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the view
|
||||
$view = 'errors/' . $errno;
|
||||
self::log('Loading view ' . $view);
|
||||
// Load the layout
|
||||
$layout = 'errors/' . $errno;
|
||||
self::log('Loading layout ' . $layout);
|
||||
|
||||
// Try and load the view, if impossible, load HTTP code instead.
|
||||
// Try and load the layout, if impossible, load HTTP code instead.
|
||||
$factory = Factory::getInstance();
|
||||
try {
|
||||
$factory->Layout->reset();
|
||||
$factory->Layout->view($view);
|
||||
$factory->Layout->display($layout);
|
||||
} catch (LayoutException $exception) {
|
||||
// No error page could be found, just echo the result
|
||||
$factory->output->set_output("<h1>$errno</h1><h3>" . $http_codes[$errno] . '</h3>');
|
||||
|
|
|
@ -73,7 +73,7 @@ class LoggerTracyBridge implements IBarPanel {
|
|||
public function getTab()
|
||||
{
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . '/Views/view.tracyloggertab.php';
|
||||
require dirname(__DIR__) . '/Layout/layout.tracyloggertab.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ class LoggerTracyBridge implements IBarPanel {
|
|||
|
||||
// Parse the panel
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . '/Views/view.tracyloggerpanel.php';
|
||||
require dirname(__DIR__) . '/Layout/layout.tracyloggerpanel.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ class Output {
|
|||
* with any server headers and profile data. It also stops benchmark
|
||||
* timers so the page rendering speed and memory usage can be shown.
|
||||
*
|
||||
* Note: All "view" data is automatically put into $this->final_output
|
||||
* Note: All "layout" data is automatically put into $this->final_output
|
||||
* by controller class.
|
||||
*
|
||||
* @uses Output::$final_output
|
||||
|
|
|
@ -75,7 +75,7 @@ class LatteEngine implements TemplateEngine
|
|||
* Handle and retrieve a template file.
|
||||
*
|
||||
* @param string $file Template File
|
||||
* @param array $assigned_variables All the variables used in this view
|
||||
* @param array $assigned_variables All the variables used in this layout
|
||||
*
|
||||
* @return string Output of the template
|
||||
*/
|
||||
|
|
|
@ -51,7 +51,7 @@ interface TemplateEngine
|
|||
* Handle and retrieve a template file.
|
||||
*
|
||||
* @param string $file Template File
|
||||
* @param array $assigned_variables All the variables used in this view
|
||||
* @param array $assigned_variables All the variables used in this layout
|
||||
*
|
||||
* @return string Output of the template
|
||||
*/
|
||||
|
|
|
@ -66,17 +66,17 @@ class layoutTest extends CoreTestAbstract
|
|||
|
||||
// Basic path
|
||||
$this->factory->layout->setFileFromString('test', 'tests/layout/testGetFilePath/', $extensions);
|
||||
$this->assertEquals('tests/layout/testGetFilePath/view.test.php', $this->factory->layout->getFile());
|
||||
$this->assertEquals('tests/layout/testGetFilePath/layout.test.php', $this->factory->layout->getFile());
|
||||
$this->assertEquals('tests/layout/testGetFilePath/', $this->factory->layout->getDirectory());
|
||||
|
||||
// Alternate file extension
|
||||
$this->factory->layout->setFileFromString('JSON', 'tests/layout/testGetFilePath/', $extensions);
|
||||
$this->assertEquals('tests/layout/testGetFilePath/view.JSON.json', $this->factory->layout->getFile());
|
||||
$this->assertEquals('tests/layout/testGetFilePath/layout.JSON.json', $this->factory->layout->getFile());
|
||||
$this->assertEquals('tests/layout/testGetFilePath/', $this->factory->layout->getDirectory());
|
||||
|
||||
// Complex deeper path
|
||||
$this->factory->layout->setFileFromString('Deeper/test', 'tests/layout/testGetFilePath/', $extensions);
|
||||
$this->assertEquals('tests/layout/testGetFilePath/Deeper/view.test.php', $this->factory->layout->getFile());
|
||||
$this->assertEquals('tests/layout/testGetFilePath/Deeper/layout.test.php', $this->factory->layout->getFile());
|
||||
$this->assertEquals('tests/layout/testGetFilePath/', $this->factory->layout->getDirectory());
|
||||
}
|
||||
|
||||
|
@ -125,13 +125,13 @@ class layoutTest extends CoreTestAbstract
|
|||
$this->assertEquals('Retrieved Data', $this->factory->layout->get('test', $directory));
|
||||
}
|
||||
|
||||
public function testLayoutView()
|
||||
public function testLayoutDisplay()
|
||||
{
|
||||
// Directory of these tests
|
||||
$directory = 'tests/layout/testLayoutGet/';
|
||||
|
||||
ob_start();
|
||||
$this->factory->layout->view('test', $directory);
|
||||
$this->factory->layout->display('test', $directory);
|
||||
Factory::getInstance()->output->_display();
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
@ -154,7 +154,7 @@ class layoutTest extends CoreTestAbstract
|
|||
|
||||
// Test for default values
|
||||
$this->assertFalse($this->factory->layout->getTitle());
|
||||
$this->assertTrue(strpos($this->factory->layout->getDirectory(), 'application/Views') !== false);
|
||||
$this->assertTrue(strpos($this->factory->layout->getDirectory(), 'application/Layout') !== false);
|
||||
}
|
||||
|
||||
public function testGetEngineFromExtension()
|
||||
|
@ -188,7 +188,7 @@ class layoutTest extends CoreTestAbstract
|
|||
$mock->method('get')->willReturn('output');
|
||||
|
||||
// And listen for usage
|
||||
$mock->expects($this->once())->method('get')->with('tests/layout/testCustomEngine/view.test.test');
|
||||
$mock->expects($this->once())->method('get')->with('tests/layout/testCustomEngine/layout.test.test');
|
||||
|
||||
// Register the engine
|
||||
$this->factory->layout->registerEngine($mock, 'Custom', array('test'));
|
||||
|
@ -209,7 +209,7 @@ class layoutTest extends CoreTestAbstract
|
|||
$this->factory->layout->registerEngine($mock, 'Custom', array('test'));
|
||||
}
|
||||
|
||||
public function testEnginesLoadView()
|
||||
public function testEnginesLoadLayout()
|
||||
{
|
||||
// Directory of these tests
|
||||
$directory = 'tests/layout/testEngines/';
|
||||
|
|
|
@ -34,9 +34,9 @@ use FuzeWorks\Factory;
|
|||
use FuzeWorks\EventPriority;
|
||||
|
||||
/**
|
||||
* Class LayoutLoadViewEventTest.
|
||||
* Class LayoutLoadEventTest.
|
||||
*/
|
||||
class layoutLoadViewEventTest extends CoreTestAbstract
|
||||
class layoutLoadEventTest extends CoreTestAbstract
|
||||
{
|
||||
|
||||
protected $factory;
|
||||
|
@ -52,10 +52,10 @@ class layoutLoadViewEventTest extends CoreTestAbstract
|
|||
*/
|
||||
public function test_basic()
|
||||
{
|
||||
$mock = $this->getMockBuilder(MockLayoutViewEventTest::class)->setMethods(['mockMethod'])->getMock();
|
||||
$mock = $this->getMockBuilder(MockLayoutEventTest::class)->setMethods(['mockMethod'])->getMock();
|
||||
$mock->expects($this->once())->method('mockMethod');
|
||||
|
||||
Events::addListener(array($mock, 'mockMethod'), 'layoutLoadViewEvent', EventPriority::NORMAL);
|
||||
Events::addListener(array($mock, 'mockMethod'), 'layoutLoadEvent', EventPriority::NORMAL);
|
||||
|
||||
// And run the test
|
||||
$this->factory->layout->get('home');
|
||||
|
@ -68,7 +68,7 @@ class layoutLoadViewEventTest extends CoreTestAbstract
|
|||
*/
|
||||
public function test_change()
|
||||
{
|
||||
Events::addListener(array($this, 'listener_change'), 'layoutLoadViewEvent', EventPriority::NORMAL);
|
||||
Events::addListener(array($this, 'listener_change'), 'layoutLoadEvent', EventPriority::NORMAL);
|
||||
$this->factory->layout->get('home');
|
||||
}
|
||||
|
||||
|
@ -77,11 +77,11 @@ class layoutLoadViewEventTest extends CoreTestAbstract
|
|||
{
|
||||
|
||||
// This controller should not exist
|
||||
$this->assertTrue(strpos($event->file, 'application/Views/view.home.php') !== false);
|
||||
$this->assertTrue(strpos($event->directory, 'application/Views/') !== false);
|
||||
$this->assertTrue(strpos($event->file, 'application/Layout/layout.home.php') !== false);
|
||||
$this->assertTrue(strpos($event->directory, 'application/Layout/') !== false);
|
||||
|
||||
// It should exist now
|
||||
$event->file = $event->directory . 'view.test.not_found';
|
||||
$event->file = $event->directory . 'layout.test.not_found';
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class layoutLoadViewEventTest extends CoreTestAbstract
|
|||
{
|
||||
|
||||
// Listen for the event and cancel it
|
||||
Events::addListener(array($this, 'listener_cancel'), 'layoutLoadViewEvent', EventPriority::NORMAL);
|
||||
Events::addListener(array($this, 'listener_cancel'), 'layoutLoadEvent', EventPriority::NORMAL);
|
||||
$this->assertFalse($this->factory->layout->get('home'));
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,6 @@ class layoutLoadViewEventTest extends CoreTestAbstract
|
|||
}
|
||||
}
|
||||
|
||||
class MockLayoutViewEventTest {
|
||||
class MockLayoutEventTest {
|
||||
public function MockMethod() {}
|
||||
}
|
Loading…
Reference in New Issue