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;
This commit is contained in:
168
core/c/form.php
168
core/c/form.php
@@ -1,169 +1,69 @@
|
||||
<?php
|
||||
namespace Nibiru;
|
||||
namespace Nibiru\Form;
|
||||
use Nibiru\Adapter;
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: stephan
|
||||
* Date: 24.01.17
|
||||
* Time: 15:48
|
||||
* User: mithril
|
||||
* Date: 26.01.18
|
||||
* Time: 20:59
|
||||
*/
|
||||
|
||||
class Form implements IForm
|
||||
{
|
||||
use Messages;
|
||||
/**
|
||||
* @desc class wide parameters
|
||||
* @var
|
||||
*/
|
||||
protected static $_instance;
|
||||
private static $fieldset_name;
|
||||
private static $action;
|
||||
private static $name;
|
||||
private static $type;
|
||||
private static $fields = array();
|
||||
private static $form = self::TYPE_FORM;
|
||||
private $_attributes = array(
|
||||
self::FORM_NAME => '',
|
||||
self::FORM_METHOD => '',
|
||||
self::FORM_ACTION => '',
|
||||
self::FORM_TARGET => ''
|
||||
);
|
||||
|
||||
protected function __construct($action, $name, $type)
|
||||
{
|
||||
try {
|
||||
if($action != "")
|
||||
{
|
||||
self::setFormAction($action);
|
||||
}
|
||||
if($name != "")
|
||||
{
|
||||
self::setFormName($name);
|
||||
}
|
||||
if($type != "")
|
||||
{
|
||||
self::setFormType($type);
|
||||
}
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
Debug::getInstance()->toDebug($e->getMessage());
|
||||
}
|
||||
}
|
||||
private $_element;
|
||||
|
||||
private static function setCurrentForm($form = self::TYPE_FORM)
|
||||
public function loadElement( $attributes )
|
||||
{
|
||||
if(self::getFieldsetName())
|
||||
{
|
||||
self::$form = self::TYPE_FORM_FIELDSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$form = $form;
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getCurrentForm()
|
||||
{
|
||||
return self::$form;
|
||||
$this->_setElement();
|
||||
$this->_setAttributes( $attributes );
|
||||
return $this->getElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method to get singleton
|
||||
*
|
||||
* @return Form
|
||||
* @return array
|
||||
*/
|
||||
public static function getInstance($action, $name, $type)
|
||||
protected function getAttributes( )
|
||||
{
|
||||
static $instance = null;
|
||||
if ($instance === null)
|
||||
{
|
||||
$instance = new Form($action, $name, $type);
|
||||
}
|
||||
return $instance;
|
||||
return $this->_attributes;
|
||||
}
|
||||
|
||||
public static function setFormAction($action)
|
||||
/**
|
||||
* @param array $attributes
|
||||
*/
|
||||
private function _setAttributes( $attributes )
|
||||
{
|
||||
try{
|
||||
if(is_string($action))
|
||||
{
|
||||
self::setCurrentForm(str_replace("{action}", $action, self::getCurrentForm()));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(Messages::msg_error_string());
|
||||
}
|
||||
} catch (\Exception $e)
|
||||
foreach( $attributes as $key=>$entry )
|
||||
{
|
||||
Debug::getInstance()->toDebug($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static function getFormAction()
|
||||
{
|
||||
return self::$action;
|
||||
}
|
||||
|
||||
public static function setFormName($name)
|
||||
{
|
||||
try{
|
||||
if(is_string($name))
|
||||
switch ($key)
|
||||
{
|
||||
self::setCurrentForm(str_replace("{name}", $name, self::getCurrentForm()));
|
||||
case array_key_exists($key, $this->_attributes):
|
||||
$this->_element = str_replace(strtoupper($key), $entry, $this->getElement());
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(Messages::msg_error_string());
|
||||
}
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
Debug::getInstance()->toDebug($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc set the form type corresponding to the HTML5 standard
|
||||
*
|
||||
* @param $type
|
||||
* @return mixed
|
||||
*/
|
||||
public static function setFormType($type)
|
||||
protected function getElement( )
|
||||
{
|
||||
try{
|
||||
if(is_string($type))
|
||||
{
|
||||
self::setCurrentForm(str_replace("{type}", $type, self::getCurrentForm()));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(Messages::msg_error_string());
|
||||
}
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
Debug::getInstance()->toDebug($e->getMessage());
|
||||
}
|
||||
return $this->_element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function getFieldsetName()
|
||||
{
|
||||
return self::$fieldset_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $fieldset_name
|
||||
*/
|
||||
private static function setFieldsetName( $fieldset_name )
|
||||
{
|
||||
self::$fieldset_name = $fieldset_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc output the form with all current fields and values
|
||||
* @param mixed $element
|
||||
*/
|
||||
public function displayForm()
|
||||
private function _setElement( )
|
||||
{
|
||||
// TODO: Implement displayForm() method.
|
||||
$this->_element = '<form action="ACTION" method="METHOD" name="NAME" target="TARGET">' . "\n" . 'FIELDS</form>' . "\n";
|
||||
}
|
||||
|
||||
public function addFieldset($name)
|
||||
{
|
||||
self::setFieldsetName($name);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user