Code style fixes
This commit is contained in:
parent
6c4c669492
commit
0868eb9c69
63 changed files with 1413 additions and 1494 deletions
|
|
@ -1,16 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form;
|
||||
|
||||
use b8\Form\Element,
|
||||
b8\View;
|
||||
b8\View;
|
||||
|
||||
class Input extends Element
|
||||
{
|
||||
protected $_required = false;
|
||||
protected $_pattern;
|
||||
protected $_validator;
|
||||
protected $_value;
|
||||
protected $_error;
|
||||
protected $_required = false;
|
||||
protected $_pattern;
|
||||
protected $_validator;
|
||||
protected $_value;
|
||||
protected $_error;
|
||||
protected $_customError = false;
|
||||
|
||||
public static function create($name, $label, $required = false)
|
||||
|
|
@ -23,89 +24,82 @@ class Input extends Element
|
|||
return $el;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRequired()
|
||||
{
|
||||
return $this->_required;
|
||||
}
|
||||
public function getRequired()
|
||||
{
|
||||
return $this->_required;
|
||||
}
|
||||
|
||||
public function setRequired($required)
|
||||
{
|
||||
$this->_required = (bool)$required;
|
||||
public function setRequired($required)
|
||||
{
|
||||
$this->_required = (bool)$required;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getValidator()
|
||||
{
|
||||
return $this->_validator;
|
||||
}
|
||||
public function getValidator()
|
||||
{
|
||||
return $this->_validator;
|
||||
}
|
||||
|
||||
public function setValidator($validator)
|
||||
{
|
||||
if(is_callable($validator) || $validator instanceof \Closure)
|
||||
{
|
||||
$this->_validator = $validator;
|
||||
}
|
||||
public function setValidator($validator)
|
||||
{
|
||||
if (is_callable($validator) || $validator instanceof \Closure) {
|
||||
$this->_validator = $validator;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->_pattern;
|
||||
}
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->_pattern;
|
||||
}
|
||||
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->_pattern = $pattern;
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->_pattern = $pattern;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if($this->getRequired() && empty($this->_value))
|
||||
{
|
||||
$this->_error = $this->getLabel() . ' is required.';
|
||||
return false;
|
||||
}
|
||||
public function validate()
|
||||
{
|
||||
if ($this->getRequired() && empty($this->_value)) {
|
||||
$this->_error = $this->getLabel() . ' is required.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->getPattern() && !preg_match('/'.$this->getPattern().'/', $this->_value))
|
||||
{
|
||||
$this->_error = 'Invalid value entered.';
|
||||
return false;
|
||||
}
|
||||
if ($this->getPattern() && !preg_match('/' . $this->getPattern() . '/', $this->_value)) {
|
||||
$this->_error = 'Invalid value entered.';
|
||||
return false;
|
||||
}
|
||||
|
||||
$validator = $this->getValidator();
|
||||
$validator = $this->getValidator();
|
||||
|
||||
if(is_callable($validator))
|
||||
{
|
||||
try
|
||||
{
|
||||
call_user_func_array($validator, array($this->_value));
|
||||
}
|
||||
catch(\Exception $ex)
|
||||
{
|
||||
$this->_error = $ex->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (is_callable($validator)) {
|
||||
try {
|
||||
call_user_func_array($validator, [$this->_value]);
|
||||
} catch (\Exception $ex) {
|
||||
$this->_error = $ex->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_customError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setError($message)
|
||||
{
|
||||
|
|
@ -114,11 +108,11 @@ class Input extends Element
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
$view->value = $this->getValue();
|
||||
$view->error = $this->_error;
|
||||
$view->pattern = $this->_pattern;
|
||||
$view->required = $this->_required;
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
$view->value = $this->getValue();
|
||||
$view->error = $this->_error;
|
||||
$view->pattern = $this->_pattern;
|
||||
$view->required = $this->_required;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue