Files
nibiru-framework.com/core/c/view.php
Stephan Kasdorf 86433af5bf Version 0.3 beta 04.02.2018
Improved: The Router now accepts actions, either trough the _action as parameter, or on the URL pattern after the controller name Example: http://youdomain/[controllername]/[actionname]/
It is now possible to load as many navigations on the page as wanted by passing the name to the JsonNavigation::getInstance()->loadJsonNavigationArray('[NAME]'); call in the navigationAction of the Controller
Building forms by simple adding the namespace use Nibiru\Factory\Form; and calling Example: Form::addInputTypeText( array( 'name' => 'lastname', 'value' => 'placeholder' ) ); To finalize the form the last call should be something like this: Form::addForm( array('name' => 'testform', 'method' => 'post', 'action' => '/' . Router::getInstance()->currentPage(), 'target' => '_self') );
The Database design has fully been refactored, now it contains an autoloading mechanism which can be triggert by createing a database folder in the application folder, a Example file is in the folder applicatoin/database
The Database access can now be implemented anywhere in your application by adding the namespace to your database accessing Logic: use Nibiru\Factory\Db;
2018-02-04 22:16:21 +01:00

139 lines
3.9 KiB
PHP
Executable File

<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 22:28
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class View extends Controller implements IView
{
private static $_instance;
const NIBIRU_SETTINGS = "SETTINGS";
const NIBIRU_SECURITY = "SECURITY";
const NIBIRU_ROUTING = "ROUTING";
const NIBIRU_FILE_END = ".tpl";
private static $smarty = array();
private static $engine = array();
/**
* @desc not part of the core should be working standalone on the
* $this->buildCsv() method
* @var int
*/
private $xmlPos = 0;
protected function __construct()
{
Controller::getInstance();
self::_setEngine();
}
public static function getInstance()
{
$className = get_called_class();
if( self::$_instance == null )
{
self::$_instance = new $className();
}
return self::$_instance;
}
/**
* @return array
*/
public function getEngine()
{
return self::$engine;
}
/**
* @param array $engine
*/
public static function _setEngine( )
{
switch(Config::getInstance()->getConfig()[Engine::T_ENGINE][Engine::T_ENGINE_NAME])
{
case Engine::T_ENGINE_SMARTY:
self::$engine = new \Smarty();
self::$engine->setTemplateDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]);
self::$engine->setCompileDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates_c"]);
self::$engine->setCacheDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"]);
self::$engine->setConfigDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["config_dir"]);
self::$engine->assign('debuging', Config::getInstance()->getConfig()[Engine::T_ENGINE]["debugbar"]);
break;
case Engine::T_ENGINE_TWIG:
$twig = new \Twig_Autoloader();
$twig::register();
self::$engine = new \Twig_Environment(new \Twig_Loader_Filesystem(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]), array(
'cache' => Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"],
));
break;
case Engine::T_ENGINE_DWOO:
// Implement Dwoo Template Engine
self::$engine = new \Dwoo\Core();
self::$engine->setCacheDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"]);
self::$engine->setCompileDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates_c"]);
self::$engine->setTemplateDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]);
self::$engine->get('debugbar.tpl', array('debuging' => Config::getInstance()->getConfig()[Engine::T_ENGINE]["debugbar"]));
break;
}
}
public function assign( $varname = array() )
{
if(is_array($varname))
{
Controller::getInstance()->varname( $this->getEngine(), $varname );
}
}
public static function forwardTo( $page )
{
header('Location: ' . $page);
exit();
}
public function display( $page )
{
preg_match_all("/".self::NIBIRU_FILE_END."/", $page, $matches);
if(!array_key_exists(self::NIBIRU_FILE_END, array_flip(array_shift($matches))))
{
$page = str_replace("/", "", $page) . self::NIBIRU_FILE_END;
}
Controller::getInstance()->action( $this->getEngine(), $page );
}
/**
* @param mixed $xmlPos
*/
protected function _setXmlPos( $xmlPos )
{
$this->xmlPos = $xmlPos;
}
/**
* @return mixed
*/
protected function getXmlPos( )
{
return $this->xmlPos;
}
protected static function printStuffToScreen( $stuff, $die = false )
{
$output = "<pre>" . print_r( $stuff, true ) . "</pre>";
if( $die )
{
die( $output );
}
else
{
return $output;
}
}
}