Skip to content

Commit

Permalink
Merge pull request #19 from znframework/5.8
Browse files Browse the repository at this point in the history
Added Form/Html::__toString() method.
  • Loading branch information
ozanuykun committed Aug 24, 2018
2 parents 8f05fd5 + bd3dceb commit 6594aef
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 46 deletions.
14 changes: 0 additions & 14 deletions BootstrapLayouts.php
Expand Up @@ -25,26 +25,12 @@ trait BootstrapLayouts
*/
protected $bootstrapGridsystemRow = NULL;


/**
* Protected bootstrap grid sytem column count
*
* @var int
*/
protected $bootstrapGridsystemColumnCount = 0;

/**
* Magic to string
*
* @return string
*/
public function __toString()
{
if( $this->getBootstrapGridsystem() )
{
return $this->createBootstrapGridsystem();
}
}

/**
* Container fluid
Expand Down
52 changes: 32 additions & 20 deletions Form.php
Expand Up @@ -62,9 +62,9 @@ class Form
* 2. application => application/x-www-form-urlencoded
* 3. text => text/plain
*
* @return string
* @return string|object
*/
public function open(String $name = NULL, Array $_attributes = []) : String
public function open(String $name = NULL, Array $_attributes = [])
{
$this->setFormName($name, $_attributes);

Expand All @@ -86,7 +86,9 @@ public function open(String $name = NULL, Array $_attributes = []) : String

$this->_unsetopen();

return $return;
$this->outputElement .= $return;

return $this;
}

/**
Expand Down Expand Up @@ -118,13 +120,15 @@ public function validateErrorArray()
*
* @param void
*
* @return string
* @return string|object
*/
public function close() : String
public function close()
{
unset($this->settings['getrow']);

return '</form>'.EOL;
$this->outputElement .= '</form>' . EOL;

return $this;
}

/**
Expand All @@ -134,9 +138,9 @@ public function close() : String
* @param string $value = NULL
* @param array $_attributes = []
*
* @return string
* @return string|object
*/
public function datetimeLocal(String $name = NULL, String $value = NULL, Array $_attributes = []) : String
public function datetimeLocal(String $name = NULL, String $value = NULL, Array $_attributes = [])
{
return $this->_input($name, $value, $_attributes, 'datetime-local');
}
Expand All @@ -148,9 +152,9 @@ public function datetimeLocal(String $name = NULL, String $value = NULL, Array $
* @param string $value = NULL
* @param array $_attributes = []
*
* @return string
* @return string|object
*/
public function textarea(String $name = NULL, String $value = NULL, Array $_attributes = []) : String
public function textarea(String $name = NULL, String $value = NULL, Array $_attributes = [])
{
$this->setNameAttribute($name);

Expand All @@ -176,7 +180,11 @@ public function textarea(String $name = NULL, String $value = NULL, Array $_attr

$this->createTextareaElementByValueAndAttributes($value, $_attributes, $return);

return $this->_perm($perm, $return);
$this->createBootstrapFormInputElementByType('textarea', $return, $_attributes, $return);

$this->outputElement .= $this->_perm($perm, $return);

return $this;
}

/**
Expand All @@ -188,9 +196,9 @@ public function textarea(String $name = NULL, String $value = NULL, Array $_attr
* @param array $_attributes = []
* @param bool $multiple = false
*
* @return string
* @return string|object
*/
public function select(String $name = NULL, Array $options = [], $selected = NULL, Array $_attributes = [], Bool $multiple = false) : String
public function select(String $name = NULL, Array $options = [], $selected = NULL, Array $_attributes = [], Bool $multiple = false)
{
$this->isTableOrQueryData($options);

Expand Down Expand Up @@ -232,7 +240,9 @@ public function select(String $name = NULL, Array $options = [], $selected = NUL

$this->_unsetselect();

return $this->_perm($perm, $return);
$this->outputElement .= $this->_perm($perm, $return);

return $this;
}

/**
Expand All @@ -243,9 +253,9 @@ public function select(String $name = NULL, Array $options = [], $selected = NUL
* @param mixed $selected = NULL
* @param array $_attributes = []
*
* @return string
* @return string|object
*/
public function multiselect(String $name = NULL, Array $options = [], $selected = NULL, Array $_attributes = []) : String
public function multiselect(String $name = NULL, Array $options = [], $selected = NULL, Array $_attributes = [])
{
return $this->select($name, $options, $selected, $_attributes, true);
}
Expand All @@ -258,7 +268,7 @@ public function multiselect(String $name = NULL, Array $options = [], $selected
*
* @return string
*/
public function hidden($name = NULL, String $value = NULL) : String
public function hidden($name = NULL, String $value = NULL)
{
$name = $this->settings['attr']['name' ] ?? $name ;
$value = $this->settings['attr']['value'] ?? $value;
Expand All @@ -276,7 +286,9 @@ public function hidden($name = NULL, String $value = NULL) : String
$hiddens = $this->createHiddenElement($name, $value);
}

return $hiddens;
$this->outputElement .= $hiddens;

return $this;
}

/**
Expand All @@ -286,9 +298,9 @@ public function hidden($name = NULL, String $value = NULL) : String
* @param string $value = NULL
* @param array $_attributes = []
*
* @return string
* @return string|object
*/
public function file(String $name = NULL, Bool $multiple = false, Array $_attributes = []) : String
public function file(String $name = NULL, Bool $multiple = false, Array $_attributes = [])
{
if( ! empty($this->settings['attr']['multiple']) )
{
Expand Down
34 changes: 24 additions & 10 deletions Html.php
Expand Up @@ -408,11 +408,11 @@ public function multiAttr(String $str, Array $array = []) : String
*
* @return string
*/
public function meta($name, String $content = NULL) : String
public function meta($name, String $content = NULL)
{
if( ! is_array($name) )
{
return $this->_singleMeta($name, $content);
$this->outputElement .= $this->_singleMeta($name, $content);
}
else
{
Expand All @@ -423,8 +423,10 @@ public function meta($name, String $content = NULL) : String
$metas .= $this->_singleMeta($key, $val);
}

return $metas;
$this->outputElement .= $metas;
}

return $this;
}

/**
Expand All @@ -436,7 +438,9 @@ protected function _content($html, $type)

$perm = $this->settings['attr']['perm'] ?? NULL;

return $this->_perm($perm, "<$type>" . $this->stringOrCallback($html) . "</$type>");
$this->outputElement .= $this->_perm($perm, "<$type>" . $this->stringOrCallback($html) . "</$type>");

return $this;
}

/**
Expand All @@ -450,7 +454,9 @@ protected function _contentAttribute($content, $_attributes, $type)

$return = '<'.$type.$this->attributes($_attributes).'>'.$this->stringOrCallback($content)."</$type>".EOL;

return $this->_perm($perm, $return);
$this->outputElement .= $this->_perm($perm, $return);

return $this;
}

/**
Expand All @@ -460,7 +466,9 @@ protected function _media($src, $_attributes, $type)
{
$perm = $this->settings['attr']['perm'] ?? NULL;

return $this->_perm($perm, '<'.strtolower($type).'src="'.$src.'"'.$this->attributes($_attributes).'>'.EOL);
$this->outputElement .= $this->_perm($perm, '<'.strtolower($type).'src="'.$src.'"'.$this->attributes($_attributes).'>'.EOL);

return $this;
}

/**
Expand All @@ -472,7 +480,9 @@ protected function _mediaContent($src, $content, $_attributes, $type)

$perm = $this->settings['attr']['perm'] ?? NULL;

return $this->_perm($perm, '<'.$type.'src="'.$src.'"'.$this->attributes($_attributes).'>'.$this->stringOrCallback($content)."</$type>".EOL);
$this->outputElement .= $this->_perm($perm, '<'.$type.'src="'.$src.'"'.$this->attributes($_attributes).'>'.$this->stringOrCallback($content)."</$type>".EOL);

return $this;
}

/**
Expand All @@ -484,7 +494,9 @@ protected function _multiElement($element, $str, $attributes = [])

$perm = $this->settings['attr']['perm'] ?? NULL;

return $this->_perm($perm, '<'.$element.$this->attributes($attributes).'>'.$this->stringOrCallback($str).'</'.$element.'>');
$this->outputElement .= $this->_perm($perm, '<'.$element.$this->attributes($attributes).'>'.$this->stringOrCallback($str).'</'.$element.'>');

return $this;
}

/**
Expand All @@ -494,7 +506,9 @@ protected function _singleElement($element, $attributes = [])
{
$perm = $this->settings['attr']['perm'] ?? NULL;

return $this->_perm($perm, '<'.strtolower($element).$this->attributes($attributes).'>');
$this->outputElement .= $this->_perm($perm, '<'.strtolower($element).$this->attributes($attributes).'>');

return $this;
}

/**
Expand Down Expand Up @@ -524,6 +538,6 @@ protected function _singleMeta($name, $content)
$content = '';
}

return '<meta'.$name.$content.' />'."\n";
return '<meta' . $name . $content . ' />' . EOL;
}
}
40 changes: 40 additions & 0 deletions OutputElements.php
@@ -0,0 +1,40 @@
<?php namespace ZN\Hypertext;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/


trait OutputElements
{
/**
* Protected output element
*
* @var string
*/
protected $outputElement = NULL;

/**
* Magic to string
*
* @return string
*/
public function __toString()
{
if( $outputElement = ($this->outputElement ?? NULL) )
{
$this->outputElement = NULL;

return $outputElement;
}
elseif( $this->getBootstrapGridsystem() )
{
return $this->createBootstrapGridsystem();
}
}
}
6 changes: 4 additions & 2 deletions ViewCommonTrait.php
Expand Up @@ -18,7 +18,7 @@

trait ViewCommonTrait
{
use CallableElements, FormElementsTrait, HtmlElementsTrait, BootstrapAttributes;
use OutputElements, CallableElements, FormElementsTrait, HtmlElementsTrait, BootstrapAttributes;

/**
* Keeps settings
Expand Down Expand Up @@ -370,7 +370,9 @@ protected function _input($name = '', $value = '', $attributes = [], $type = '')

$this->createBootstrapFormInputElementByType($type, $return, $attributes, $return);

return $this->_perm($perm, $return);
$this->outputElement .= $this->_perm($perm, $return);

return $this;
}

/**
Expand Down

0 comments on commit 6594aef

Please sign in to comment.