REFACTORING: updated the base template with some examples, also added annotations for autocomplete in the core view and controller core.

This commit is contained in:
Stephan Kasdorf
2019-11-03 23:30:44 +01:00
parent 70dccc3f15
commit 7306db234e
20 changed files with 291 additions and 132 deletions

View File

@@ -13,6 +13,11 @@ use Nibiru;
abstract class Controller extends Nibiru\Controller implements IController
{
public function __construct()
{
//basic constructor for the Controller can be overwritten
}
/**
* This should be part of any extended controller
* class in order to implement a page structure

View File

@@ -16,6 +16,9 @@ class Auth extends Controller implements IAuth
private $_username = "";
private $_password = "";
/**
* Auth constructor.
*/
protected function __construct()
{
parent::__construct();
@@ -23,7 +26,10 @@ class Auth extends Controller implements IAuth
}
public static function getInstance()
/**
* @return View
*/
public static function getInstance(): View
{
$className = get_called_class();
if( self::$_instance == null )
@@ -33,6 +39,11 @@ class Auth extends Controller implements IAuth
return self::$_instance;
}
/**
* @param $login
* @param $password
* @return bool
*/
public function auth( $login, $password )
{
// TODO: Implement auth($username, $password) method.
@@ -41,7 +52,7 @@ class Auth extends Controller implements IAuth
if(!array_key_exists('auth', $_SESSION))
{
$user_password = Pdo::query("SELECT DES_DECRYPT(user_pass, '".Config::getInstance()->getConfig()["SECURITY"]["password_hash"]."') AS pass FROM user WHERE user_login = '".$login."';");
$user_password = Pdo::query("SELECT DES_DECRYPT(user_pass, '".Config::getInstance()->getConfig()[IView::NIBIRU_SECURITY]["password_hash"]."') AS pass FROM user WHERE user_login = '".$login."';");
if( $user_password["pass"] == $password )
{
$session_id = session_id();
@@ -103,23 +114,4 @@ class Auth extends Controller implements IAuth
{
$this->_password = $password;
}
/**
* This should be part of any extended controller
* class in order to implement a page structure
* @return array
*/
public function pageAction()
{
// TODO: Implement pageAction() method.
}
/**
* This is the part where you can add titles to
* your page navigation.
*/
public function navigationAction()
{
// TODO: Implement navigationAction() method.
}
}

View File

@@ -25,7 +25,7 @@ class Controller extends View
$this->_setConfig(Config::getInstance()->getConfig());
}
public static function getInstance()
public static function getInstance(): View
{
$className = get_called_class();
if( self::$_instance == null )

View File

@@ -22,7 +22,7 @@ class JsonNavigation extends Config
private static $_name = false;
private static $_section_name = self::NAVIGATION;
public static function getInstance()
public static function getInstance(): JsonNavigation
{
parent::getInstance();
self::setFileContentString();
@@ -36,7 +36,7 @@ class JsonNavigation extends Config
/**
* @return string
*/
protected static function getSectionName()
protected static function getSectionName(): string
{
return self::$_section_name;
}
@@ -44,23 +44,23 @@ class JsonNavigation extends Config
/**
* @param string $section_name
*/
private static function setSectionName( $section_name )
private static function setSectionName( string $section_name )
{
self::$_section_name = $section_name;
}
/**
* @return boolean
*/
protected static function getName()
/**
* @return string
*/
protected static function getName(): string
{
return self::$_name;
}
/**
* @param boolean $name
*/
private static function setName( $name )
/**
* @param $name
*/
private static function setName( string $name )
{
self::$_name = $name;
}
@@ -74,7 +74,7 @@ class JsonNavigation extends Config
}
/**
* @param null $file_content
* Content String
*/
private static function setFileContentString( )
{
@@ -84,30 +84,31 @@ class JsonNavigation extends Config
/**
* @return array
*/
protected static function getFileContentArray( )
protected static function getFileContentArray( ): array
{
return self::$_file_content_array;
}
/**
* @param array $file_content_array
* will set the file Content array
*/
private static function setFileContentArray( )
{
self::$_file_content_array = file( Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"][self::getSectionName()] );
}
/**
* @return array
*/
protected static function getNavigation( )
/**
* @return \RecursiveIteratorIterator
*/
protected static function getNavigation( ): \RecursiveIteratorIterator
{
return self::$_navigation;
}
/**
* @param array $navigation
*/
/**
* Will load the navigation json file to the $_navigation
* variable
*/
private static function setNavigation( )
{
self::$_navigation = new \RecursiveIteratorIterator(
@@ -139,8 +140,9 @@ class JsonNavigation extends Config
/**
* Loads the navigation from a json file into
* the view, making the variables available
*/
public function loadJsonNavigationArray( $name = false )
* @param string $name
*/
public function loadJsonNavigationArray( string $name = '' )
{
if( $name )
{

View File

@@ -12,14 +12,6 @@ class View implements IView
{
private static $_instance;
const NIBIRU_SETTINGS = "SETTINGS";
const NIBIRU_URL = "pageurl";
const NIBIRU_ERROR = "ERROR";
const NIBIRU_SECURITY = "SECURITY";
const NIBIRU_ROUTING = "ROUTING";
const NIBIRU_EMAIL = "EMAIL";
const NIBIRU_FILE_END = ".tpl";
private static $smarty = array();
private static $engine = array();
@@ -36,7 +28,10 @@ class View implements IView
self::_setEngine();
}
public static function getInstance()
/**
* @return View
*/
public static function getInstance(): View
{
$className = get_called_class();
if( self::$_instance == null )
@@ -47,7 +42,18 @@ class View implements IView
}
/**
* @return array
* @param array $varname
*/
public static function assign( $varname = array() )
{
if(is_array($varname))
{
Controller::getInstance()->varname( self::getInstance()->getEngine(), $varname );
}
}
/**
* @return \Smarty
*/
public function getEngine(): \Smarty
{
@@ -68,17 +74,6 @@ class View implements IView
self::$engine->assign('debuging', Config::getInstance()->getConfig()[Engine::T_ENGINE]["debugbar"]);
}
/**
* @param array $varname
*/
public function assign( $varname = array() )
{
if(is_array($varname))
{
Controller::getInstance()->varname( $this->getEngine(), $varname );
}
}
/**
* @param $page
*/

View File

@@ -42,7 +42,7 @@ class Form
* @desc is used internaly for assambly only
* @param $option
*/
private static function assambleOptions( $option )
private static function assembleOptions( $option )
{
if($option == false)
{
@@ -76,7 +76,7 @@ class Form
* @desc is used internally for assambly only
* @param $element
*/
private static function assamble( $element )
private static function assemble( $element )
{
if( self::getDiv() )
{
@@ -174,7 +174,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeText() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -188,7 +188,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeSubmit() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -202,7 +202,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeTextarea() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -217,7 +217,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeRadio() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -231,7 +231,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeCheckbox() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -245,7 +245,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypePassword() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -259,7 +259,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeDate() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -273,7 +273,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeEmail() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -287,7 +287,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeColor() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -301,7 +301,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeDatetime() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -315,7 +315,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeFileUpload() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -329,7 +329,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeHidden() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -343,7 +343,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeImageSubmit() );
self::assamble( self::getElement()->loadElement( $attrbutes ) );
self::assemble( self::getElement()->loadElement( $attrbutes ) );
}
/**
@@ -357,7 +357,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeNumber() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -372,7 +372,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeRange() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -386,7 +386,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeReset() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -400,7 +400,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeSearch() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -414,7 +414,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeTelefon() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -428,7 +428,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeUrl() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -443,8 +443,8 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeSelect() );
self::assamble( self::displaySelect( self::getElement()->loadElement( $attributes ) ) );
self::assambleOptions( false );
self::assemble( self::displaySelect( self::getElement()->loadElement( $attributes ) ) );
self::assembleOptions( false );
}
/**
@@ -459,7 +459,7 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeButton() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -469,7 +469,7 @@ class Form
public static function addSelectOption( $attributes )
{
self::setElement( new TypeOption() );
self::assambleOptions( self::getElement()->loadElement( $attributes ) );
self::assembleOptions( self::getElement()->loadElement( $attributes ) );
}
/**
@@ -483,6 +483,6 @@ class Form
self::setDiv( $div );
}
self::setElement( new TypeLabel() );
self::assamble( self::getElement()->loadElement( $attributes ) );
self::assemble( self::getElement()->loadElement( $attributes ) );
}
}

View File

@@ -10,5 +10,11 @@ namespace Nibiru;
*/
interface IView
{
const NIBIRU_SETTINGS = "SETTINGS";
const NIBIRU_URL = "pageurl";
const NIBIRU_ERROR = "ERROR";
const NIBIRU_SECURITY = "SECURITY";
const NIBIRU_ROUTING = "ROUTING";
const NIBIRU_EMAIL = "EMAIL";
const NIBIRU_FILE_END = ".tpl";
}